/**
 *
 * @(#)author  [OK]
 * @(#)version 1.0
 * @(#)date    2014-08-07
 * @(#)since   JDK 1.6.2
 *
 * Copyright (c) www.udapsoft.co.kr, Inc.
 * All rights reserved.
 */
 package kr.co.udapsoft.ebid.buyer.payment.purchase.biz;


import java.util.ArrayList;

import oracle.toplink.internal.ox.StrBuffer;
import kr.co.hsnc.common.base.WAFLogger;
import kr.co.hsnc.common.base.WAFMessages;
import kr.co.hsnc.common.logger.Logger;
import kr.co.hsnc.common.sql.Row;
import kr.co.hsnc.common.sql.RowSet;
import kr.co.hsnc.common.sql.RowSetImpl;
import kr.co.hsnc.common.sql.WAFSQLException;
import kr.co.hsnc.common.sql.persistent.Persistent;
import kr.co.hsnc.common.sql.persistent.PersistentImpl;
import kr.co.hsnc.common.sql.search.Search;
import kr.co.hsnc.common.sql.search.SearchImpl;
import kr.co.hsnc.common.sql.util.RowSetUtility;
import kr.co.hsnc.common.util.ValueObject;
import kr.co.udapsoft.common.sender.MessageSend;
import kr.co.udapsoft.ebid.buyer.common.file.FileManager;

import com.udapsoft.waf.system.Biz;
import com.udapsoft.waf.system.HandlerStorage;

public class PayInstallResultBiz extends Biz {
	
	public PayInstallResultBiz(HandlerStorage storage) {
		super(storage);
	}
	
	public void doBiz() throws Exception {

		WAFLogger.debug("전자조달.대금관리.구매.대금신청상세(설치) 프로세스처리.[PayInstallResultBiz]");
		WAFLogger.debug("상세 선택 데이터 key="+params.get("purContId"));
		WAFLogger.debug("상세 선택 데이터 key="+params.get("payreqId"));
		ValueObject user = storage.getUser();
		String acctId = user.get("ACCT_ID");
		
		if(storage.compareEvent("")){
			
			WAFLogger.debug("[PayInstallResultBiz] INIT");
			//신청구분ComboList
			//RowSet rowSet = getPerpayReqDiv();
			//storage.addRowSet("perpayReqDivComboList", rowSet);
			
			//계약정보, 세금계산서정보, 대금정보  
			ValueObject prePayment = getPayItem(params);
			String PayItemListId = prePayment.get("PAYREQ_ID");
			
			//환률기준일자
			String rateDy = prePayment.get("TAX_DY");
			String reqPrepaySupplyAmt = prePayment.get("CUR_REQ_AMT");
			String inputVat = prePayment.get("CHG_CODE10");
						
			//분계유형
			ValueObject contInfo = getContInfo(params);
			String guaGb = contInfo.get("GUA_GB");
            storage.addValueObject("ContInfo", contInfo);

            String curGb =  prePayment.get("CURRENCY_GB");
			String rateEx = "0";
			String rateAmt = "0";
			String rateVamt = "0";
			if(!"KRW".equals(curGb)){
				ValueObject rowObject = getRageEx(rateDy, curGb, reqPrepaySupplyAmt, inputVat);
				rateEx = rowObject.get("RATE");
				rateAmt = rowObject.get("RATE_AMT");
				rateVamt = rowObject.get("RATE_VAMT");
			}
			prePayment.set("rateEx", rateEx);
			prePayment.set("rateAmt", rateAmt);
			prePayment.set("rateVamt", rateVamt);
			
			//대금내역
			//RowSet prePaymentList = getPayItemList(PayItemListId);
			//storage.addRowSet("prePaymentList", prePaymentList);
			
			//첨부파일
	        //storage.addValueObject("PREPAYMENTS_GIVEUP", getfilelist("PREPAYMENTS_GIVEUP",prePayment.get("PREPAY_ID"),"PREPAYMENTS_GIVEUP"));
	        //storage.addValueObject("TAX_BILL", getfilelist("TAX_BILL",prePayment.get("PREPAY_ID"),"TAX_BILL"));

			//보증정보
			params.set("selectSubContModId", prePayment.get("PUR_CONT_MOD_ID"));
			//지급구분에 따라서 보증 쿼리 변경 DEPOSIT_CD
			params.set("depositCD", prePayment.get("DEPOSIT_CD"));
			RowSet contOutWarr = getContOutWarr(params);
			storage.addRowSet("contOutWarr", contOutWarr);
			
	 	    // 각국 통화코드에 따른 소숫점 이하 자릿수 구하기
	        RowSet rowSetGb = getUseCurrencyGBRowSet();
	        storage.addRowSet("digitRowSet", rowSetGb);  
	        
	        // 계약통화 자릿수 구하기
	        String digit = getDigit(rowSetGb, (String)prePayment.get("CURRENCY_GB"));
	        prePayment.set("digit", digit);
	        
			storage.addValueObject("prePayment", prePayment);
			
			//기타서류 첨부파일 조회
		    RowSet purchaseFileRow = getfileListRowSet("PURCHASE_"+PayItemListId, "");
		    storage.addRowSet("purchaseFileRow", purchaseFileRow);
		    
		    //Vendor Print  
            ValueObject vendorPrintInfo = getVendorPrint(params);
            storage.addValueObject("vendorPrintInfo", vendorPrintInfo);
            
            //설계평가  
            ValueObject planApprInfo = getPlanApprInfo(params);
            storage.addValueObject("planApprInfo", planApprInfo);
            
		}else if(storage.compareEvent("DELETE_DATA")){
			
			WAFLogger.debug("[PayInstallResultBiz] DELETE_DATA");
			
			Persistent persistent_d = null;
			String sqlstr_d = "";

			try {
			
				//C:토건, B:플랜트 구분조회
				//String gubun = getGubun();
				
				//구매_대금지급신청 삭제
				delPur1100t();
				
				//구매_대금지급 내역 삭제
				delPmmPayreqItem();
				
				//구분에 따른 입고 테이블 변경
/*				if(gubun.equals("C")){
					updatePmmStock();
				}else{
					updateShippingList();
					updateWarehouse();
				}*/

				updateContPurPayplan();
				
				super.storage.setSuccess(true);
	        }
	        catch(Exception e) {
	            super.doException(e);
	            super.storage.setMessage(e.getMessage());
	            super.storage.setDetailMessage(e);
	            super.conn.setRollback();
	        	super.storage.setSuccess(false);
	        }
	        finally {
	        	super.conn.end();
	        }
			
		}else if(storage.compareEvent("SAVE_DATA")){
			
			WAFLogger.debug("[PayInstallResultBiz] SAVE_DATA");
			
			Persistent persistent_i = null;
			Persistent persistent_u = null;
			String sqlstr_i = "";
			String sqlstr_u = "";

			Persistent persistent_u2 = null;
			String sqlstr_u2 = "";

			try {
			
				//대금 신청 상제 정보
				String payreqId					= params.get("payreqId");				//지급신청ID
				String taxMethodCd				= params.get("chk_info");				//세금계산서발행방법
				String taxDy					= params.get("date1");					//작성일자(증빙일자)
				String taxChargNm				= params.get("userName");				//담당자명
				String taxChargHp				= params.get("hp");						//담당자 핸드폰번호
				String taxChargEmail			= params.get("eMail");					//담당자 이메일
				String selectDepositCd			= params.get("selectDepositCd");		//지급구분
				
				String befAcmpApplyAmt			= params.get("befAcmpApplyAmt");		//전회 청구 공급가액
				String befAcmpVat				= params.get("befAcmpVat");				//전회 청구 부가세
				String befAcmpAmt				= params.get("befAcmpAmt");				//전회 청구 합계
				String befAcmpPercent			= params.get("befAcmpPercent");			//전회 청구 지급율
				
				String curAcmpApplyamt			= params.get("curAcmpApplyamt");		//금회 청구 공급가액
				String curAcmpVat				= params.get("curAcmpVat");				//금회 청구 부가세
				String curAcmpAmt				= params.get("curAcmpAmt");				//금회 청구 합계
				String curAcmpPercent			= params.get("curAcmpPercent");			//금회 청구 지급율
				
				String curBefAcmpSupplyamt		= params.get("curBefAcmpSupplyamt");	//누계 청구 공급가액
				String curBefAcmpVat			= params.get("curBefAcmpVat");			//누계 청구 부가세
				String curBefAcmpAmt			= params.get("curBefAcmpAmt");			//누계 청구 합계
				String curBefAcmpPercent		= params.get("curBefAcmpPercent");		//누계 청구 지급율
				
				String remainderAcmpSupplyamt	= params.get("remainderAcmpSupplyamt");	//잔여 청구 공급가액
				String remainderAcmpVat			= params.get("remainderAcmpVat");		//잔여 청구 부가세
				String remainderAcmpAmt			= params.get("remainderAcmpAmt");		//잔여 청구 합계
				String remainderAcmpPercent		= params.get("remainderAcmpPercent");	//잔여 청구 지급율
				
				String befPrepayApplyAmt		= params.get("befPrepayApplyAmt");		//전회 선급반제 공급가액
				String befPrepayVat				= params.get("befPrepayVat");			//전회 선급반제 부가세
				String befPrepayAmt				= params.get("befPrepayAmt");			//전회 선급반제 합계
				String befPrepayPercent			= params.get("befPrepayPercent");		//전회 선급반제 지급율
				
				String curPrepayApplyamt		= params.get("curPrepayApplyamt");		//금회 선급반제 공급가액
				String curPrepayVat				= params.get("curPrepayVat");			//금회 선급반제 부가세
				String curPrepayDeductamt		= params.get("curPrepayDeductamt");		//금회 선급반제 합계
				String curPrepayPercent			= params.get("curPrepayPercent");		//금회 선급반제 지급율
				
				String curBefPrepaySupplyamt	= params.get("curBefPrepaySupplyamt");	//누계 선급반제 공급가액
				String curBefPrepayVat			= params.get("curBefPrepayVat");		//누계 선급반제 부가세
				String curBefPrepayAmt			= params.get("curBefPrepayAmt");		//누계 선급반제 합계
				String curBefPrepayPercent		= params.get("curBefPrepayPercent");	//누계 선급반제 지급율
				
				String remainderPrepaySupplyamt	= params.get("remainderPrepaySupplyamt");	//잔여 선급반제 공급가액
				String remainderPrepayVat		= params.get("remainderPrepayVat");			//잔여 선급반제 부가세
				String remainderPrepayAmt		= params.get("remainderPrepayAmt");			//잔여 선급반제 합계
				String remainderPrepayPercent	= params.get("remainderPrepayPercent");		//잔여 선급반제 지급율
				
				String payedApplyamt			= params.get("payedApplyamt");			//전회 실지금	공급가액
				String payedVat					= params.get("payedVat");				//전회 실지금	부가세
				String payedAmt					= params.get("payedAmt");				//전회 실지금	합계
				//String payedPercent				= params.get("payedPercent");			//전회 실지금	지급율
				
				String curReqAmt				= params.get("curReqAmt");				//금회 실지금	공급가액
				String curReqVatamt				= params.get("curReqVatamt");			//금회 실지금	부가세
				String curReqApplyamt			= params.get("curReqApplyamt");			//금회 실지금	합계
				//String curReqPercent			= params.get("curReqPercent");			//금회 실지금	지급율
				
				String curPayedSupplyamt		= params.get("curPayedSupplyamt");		//누계 실지금	공급가액
				String curPayedVat				= params.get("curPayedVat");			//누계 실지금	부가세
				String curPayedAmt				= params.get("curPayedAmt");			//누계 실지금	합계
				//String curPayedPercent			= params.get("curPayedPercent");		//누계 실지금	지급율
				
				//String remainderSupplyamt		= params.get("remainderSupplyamt");		//잔여 실지금 공급가액
				//String remainderVat				= params.get("remainderVat");			//잔여 실지금 부가세
				//String remainderAmt				= params.get("remainderAmt");			//잔여 실지금 합계
				//String remainderPercent			= params.get("remainderPercent");		//잔여 실지금 지급율
				
				String reMarks					= params.get("reMarks");				//특기사항
				String jigubsayu				= params.get("jigubsayu");
				
				String statusCd					= params.get("statusCd");
				if(taxMethodCd.equals("3")){
					statusCd					= "05";									//상태(작성중)
				}
				if("99".equals(params.get("statusCd"))){
					statusCd					= "05";									//상태(작성중)
				}
				
				String vpChkEmpNo				= params.get("VP_CHK_EMPNO");			//검토자사번
				String vpChkEmpNm				= params.get("VP_CHK_EMPNM");			//검토자명
				String vpEndDy					= params.get("VP_END_DY");				//검토일자
				
				
				String userId					= storage.getUser().get("ACCT_ID");		//로그인사용자
				
				//분계유형
				String acctGb					= params.get("acct_gb");				//분계유형
				String guaGb					= params.get("proof_cd");				//
				String payGroup					= params.get("pay_group");				//
				String paymentTerms				= params.get("payment_terms_id");			//

				//환률정보
				String rateAmt					= params.get("rateAmt").replace(",", "");				
				String rateVamt					= params.get("rateVamt").replace(",", "");			

				String creBy					= params.get("creBy");
				String updBy					= params.get("updBy");
				String by						= "";
				if("".equals(creBy)){
					by = updBy;
				}else{
					by = creBy;
				}
				
				conn.begin();
				
				persistent_u = new PersistentImpl(super.conn.getConnection());
				sqlstr_u = " UPDATE PUR1100T	      														\n"
			              + " SET    TAX_METHOD_CD    			= ?       , 					            \n"
			              + "        REQ_DATE 					= to_date(?,'YYYY-MM-DD')  ,	            \n"
			              + "        TAX_DY 					= ?       , 					            \n"
			              + "        TAX_CHARG_NM				= ?       , 					            \n"
			              + "        TAX_CHARG_HP				= ?       , 					            \n"
			              + "        TAX_CHARG_EMAIL			= ?       , 					            \n"
			              + "        DEPOSIT_CD					= ?       , 					            \n"

			              + "        BEF_ACMP_APPLYAMT			= ?       , 					            \n"
			              + "        BEF_ACMP_VAT				= ?       , 					            \n"
			              + "        BEF_ACMP_AMT				= ?       , 					            \n"
			              + "        BEF_ACMP_PERCENT			= ?       , 					            \n"
			              + "        CUR_ACMP_APPLYAMT			= ?       , 					            \n"
			              + "        CUR_ACMP_VAT				= ?       , 					            \n"
			              + "        CUR_ACMP_AMT				= ?       , 					            \n"
			              + "        CUR_ACMP_PERCENT			= ?       , 					            \n"
			              + "        CUR_BEF_ACMP_SUPPLYAMT		= ?       , 					            \n"
			              + "        CUR_BEF_ACMP_VAT			= ?       , 					            \n"
			              + "        CUR_BEF_ACMP_AMT			= ?       , 					            \n"
			              + "        CUR_BEF_ACMP_PERCENT		= ?       , 					            \n"
			              + "        REMAINDER_ACMP_SUPPLYAMT	= ?       , 					            \n"
			              + "        REMAINDER_ACMP_VAT			= ?       , 					            \n"
			              + "        REMAINDER_ACMP_AMT			= ?       , 					            \n"
			              + "        REMAINDER_ACMP_PERCENT		= ?       , 					            \n"
			              
			              + "        BEF_PREPAY_APPLYAMT		= ?       , 					            \n"
			              + "        BEF_PREPAY_VAT				= ?       , 					            \n"
			              + "        BEF_PREPAY_AMT				= ?       , 					            \n"
			              + "        BEF_PREPAY_PERCENT			= ?       , 					            \n"
			              + "        CUR_PREPAY_APPLYAMT		= ?       , 					            \n"
			              + "        CUR_PREPAY_VAT				= ?       , 					            \n"
			              + "        CUR_PREPAY_DEDUCTAMT		= ?       , 					            \n"
			              + "        CUR_PREPAY_PERCENT			= ?       , 					            \n"
			              + "        CUR_BEF_PREPAY_SUPPLYAMT	= ?       , 					            \n"
			              + "        CUR_BEF_PREPAY_VAT			= ?       , 					            \n"
			              + "        CUR_BEF_PREPAY_AMT			= ?       , 					            \n"
			              + "        CUR_BEF_PREPAY_PERCENT		= ?       , 					            \n"
			              + "        REMAINDER_PREPAY_SUPPLYAMT	= ?       , 					            \n"
			              + "        REMAINDER_PREPAY_VAT		= ?       , 					            \n"
			              + "        REMAINDER_PREPAY_AMT		= ?       , 					            \n"
			              + "        REMAINDER_PREPAY_PERCENT	= ?       , 					            \n"
			              
			              + "        PAYED_APPLYAMT				= ?       , 					            \n"
			              + "        PAYED_VAT					= ?       , 					            \n"
			              + "        PAYED_AMT					= ?       , 					            \n"
			              //+ "        PAYED_PERCENT				= ?       , 					            \n"
			              + "        CUR_REQ_AMT				= ?       , 					            \n"
			              + "        CUR_REQ_VATAMT				= ?       , 					            \n"
			              + "        CUR_REQ_APPLYAMT			= ?       , 					            \n"
			              //+ "        CUR_REQ_PERCENT			= ?       , 					            \n"
			              + "        CUR_PAYED_SUPPLYAMT		= ?       , 					            \n"
			              + "        CUR_PAYED_VAT				= ?       , 					            \n"
			              + "        CUR_PAYED_AMT				= ?       , 					            \n"
			              //+ "        CUR_PAYED_PERCENT			= ?       , 					            \n"
			              //+ "        REMAINDER_SUPPLYAMT		= ?       , 					            \n"
			              //+ "        REMAINDER_VAT				= ?       , 					            \n"
			              //+ "        REMAINDER_AMT				= ?       , 					            \n"
			              //+ "        REMAINDER_PERCENT			= ?       , 					            \n"
			              
			              + "        REQ_STATUS					= ?       , 					            \n"
			              + "        RE_MARKS					= ?       , 					            \n"
			              + "        CRE_BY      				= ?       , 					            \n"
			              + "        UPD_BY      				= ?       , 					            \n"
						  + "        ACCT_GB      				= ?       , 					            \n"
						  + "        PAY_GROUP      			= ?       , 					            \n"
						  + "        GUA_GB      				= ?       , 					            \n"
						  + "        PAYMENT_TERMS      		= ?       , 					            \n"
						  + "        REQ_CHARGE_ID      		= ?       , 					            \n"
						  
						  + "        CUR_REQ_APPLYAMT_KRW      	= ?       , 					            \n"
						  + "        CUR_REQ_VATAMT_KRW      	= ?       , 					            \n"

						  + "        UPD_DATE    				= sysdate ,									\n"
						  + "        CRE_DATE    				= sysdate ,									\n"
			              
						  + "        DEPOSIT_RESN		      	= ?       , 					            \n"
						  + "        RTN_REASON    				= ''      , 					            \n"
						  + "        TRANS_CD    				= 'N'      , 					            \n"
			              
			              + "        VP_CHK_EMPNO    			= ? ,										\n"
			              + "        VP_CHK_EMPNM    			= ? ,										\n"
			              + "        VP_END_DY    				= ? ,										\n"
			              + "        SUPP_DIRECT_YN    			= ? ,										\n"  //2016.6.15 하도급직불
			              + "        CUR_ACMP_EXCRATE    		= F_GET_EXCHANGE_RATE(TO_DATE(TAX_DY,'YYYYMMDD'),?,'KRW')	\n"  //2019.03.26 환율
			              
			              + " WHERE  PAYREQ_ID      			= ?        									\n" ;
				  
				persistent_u.setStatement(sqlstr_u);
					
				persistent_u.addParameter(taxMethodCd);
				persistent_u.addParameter(taxDy);
				persistent_u.addParameter(taxDy.replaceAll("-", ""));
				persistent_u.addParameter(taxChargNm);
				persistent_u.addParameter(taxChargHp);
				persistent_u.addParameter(taxChargEmail);
				persistent_u.addParameter(selectDepositCd);
				
				persistent_u.addParameter(befAcmpApplyAmt.replaceAll(",", ""));
				persistent_u.addParameter(befAcmpVat.replaceAll(",", ""));
				persistent_u.addParameter(befAcmpAmt.replaceAll(",", ""));
				persistent_u.addParameter(befAcmpPercent.replaceAll(",", ""));
				persistent_u.addParameter(curAcmpApplyamt.replaceAll(",", ""));
				persistent_u.addParameter(curAcmpVat.replaceAll(",", ""));
				persistent_u.addParameter(curAcmpAmt.replaceAll(",", ""));
				persistent_u.addParameter(curAcmpPercent.replaceAll(",", ""));
				persistent_u.addParameter(curBefAcmpSupplyamt.replaceAll(",", ""));
				persistent_u.addParameter(curBefAcmpVat.replaceAll(",", ""));
				persistent_u.addParameter(curBefAcmpAmt.replaceAll(",", ""));
				persistent_u.addParameter(curBefAcmpPercent.replaceAll(",", ""));
				persistent_u.addParameter(remainderAcmpSupplyamt.replaceAll(",", ""));
				persistent_u.addParameter(remainderAcmpVat.replaceAll(",", ""));
				persistent_u.addParameter(remainderAcmpAmt.replaceAll(",", ""));
				persistent_u.addParameter(remainderAcmpPercent.replaceAll(",", ""));
				
				persistent_u.addParameter(befPrepayApplyAmt.replaceAll(",", ""));
				persistent_u.addParameter(befPrepayVat.replaceAll(",", ""));
				persistent_u.addParameter(befPrepayAmt.replaceAll(",", ""));
				persistent_u.addParameter(befPrepayPercent.replaceAll(",", ""));
				persistent_u.addParameter(curPrepayApplyamt.replaceAll(",", ""));
				persistent_u.addParameter(curPrepayVat.replaceAll(",", ""));
				persistent_u.addParameter(curPrepayDeductamt.replaceAll(",", ""));
				persistent_u.addParameter(curPrepayPercent.replaceAll(",", ""));
				persistent_u.addParameter(curBefPrepaySupplyamt.replaceAll(",", ""));
				persistent_u.addParameter(curBefPrepayVat.replaceAll(",", ""));
				persistent_u.addParameter(curBefPrepayAmt.replaceAll(",", ""));
				persistent_u.addParameter(curBefPrepayPercent.replaceAll(",", ""));
				persistent_u.addParameter(remainderPrepaySupplyamt.replaceAll(",", ""));
				persistent_u.addParameter(remainderPrepayVat.replaceAll(",", ""));
				persistent_u.addParameter(remainderPrepayAmt.replaceAll(",", ""));
				persistent_u.addParameter(remainderPrepayPercent.replaceAll(",", ""));
				
				persistent_u.addParameter(payedApplyamt.replaceAll(",", ""));
				persistent_u.addParameter(payedVat.replaceAll(",", ""));
				persistent_u.addParameter(payedAmt.replaceAll(",", ""));
				//persistent_u.addParameter(payedPercent.replaceAll(",", ""));
				persistent_u.addParameter(curReqAmt.replaceAll(",", ""));
				persistent_u.addParameter(curReqVatamt.replaceAll(",", ""));
				persistent_u.addParameter(curReqApplyamt.replaceAll(",", ""));
				//persistent_u.addParameter(curReqPercent.replaceAll(",", ""));
				persistent_u.addParameter(curPayedSupplyamt.replaceAll(",", ""));
				persistent_u.addParameter(curPayedVat.replaceAll(",", ""));
				persistent_u.addParameter(curPayedAmt.replaceAll(",", ""));
				//persistent_u.addParameter(curPayedPercent.replaceAll(",", ""));
				//persistent_u.addParameter(remainderSupplyamt.replaceAll(",", ""));
				//persistent_u.addParameter(remainderVat.replaceAll(",", ""));
				//persistent_u.addParameter(remainderAmt.replaceAll(",", ""));
				//persistent_u.addParameter(remainderPercent.replaceAll(",", ""));
				
				persistent_u.addParameter(statusCd);
				persistent_u.addParameter(reMarks);
				persistent_u.addParameter(by);
				persistent_u.addParameter(userId);
				//분계유형
				persistent_u.addParameter(acctGb);
				persistent_u.addParameter(payGroup);
				persistent_u.addParameter(guaGb);
				persistent_u.addParameter(paymentTerms);

				persistent_u.addParameter(acctId);

				persistent_u.addParameter(rateAmt);
				persistent_u.addParameter(rateVamt);
				
				persistent_u.addParameter(jigubsayu);
				
				persistent_u.addParameter(vpChkEmpNo);
				persistent_u.addParameter(vpChkEmpNm);
				persistent_u.addParameter(vpEndDy.replaceAll("-", ""));
				persistent_u.addParameter(params.get("SUPP_DIRECT_YN"));   //2016.6.15 하도급직불 
				persistent_u.addParameter(params.get("conCurCd"));   //2019.03.26 환종 
				
				persistent_u.addParameter(payreqId);	//지급신청ID
					
				WAFLogger.debug(sqlstr_u);
				WAFLogger.debug(persistent_u.getParameters());
					
				persistent_u.execute();
				persistent_u.clearParameters();

				/**
				 * 2018.11.20
				 * 이인오
				 * 사용안함 경영정보 디비링크삭제
				persistent_u2 = new PersistentImpl(super.conn.getConnection());
				sqlstr_u2 = " UPDATE TAX_INT_INFO!CCSIF											\n"
						+ " SET    RTN_REASON    		= ''									\n"
						+ "        , RTN_TAX_CD    		= ''									\n"
						+ " WHERE  PAY_KEY      		= ?        								\n"
						;			  
				persistent_u2.setStatement(sqlstr_u2);
				persistent_u2.addParameter(payreqId);
					
				WAFLogger.debug(sqlstr_u2);
				WAFLogger.debug(persistent_u2.getParameters());
					
				persistent_u2.execute();
				persistent_u2.clearParameters();
				*/
				super.storage.setSuccess(true);
			}			
	        catch(Exception e) {
	            super.doException(e);
	            super.storage.setMessage(e.getMessage());
	            super.storage.setDetailMessage(e);
	            super.conn.setRollback();
	        	super.storage.setSuccess(false);
	        }
	        finally {
	        	super.conn.end();
	        }
		
		}else if(storage.compareEvent("REQ_DATA")){
			
			Persistent persistent_u = null;
			String sqlstr_u = "";

			try {
			
				//대금 신청 상제 정보
				String payreqId					= params.get("payreqId");				//지급신청ID				
				String statusCd					= "02";						//상태(01:작성중, 02:대금요청, 03:대금신청, 04:결재중, 10:결재완료, 99:반려)
				String userId					= storage.getUser().get("ACCT_ID");		//로그인사용자
				
				conn.begin();
				
				persistent_u = new PersistentImpl(super.conn.getConnection());

				sqlstr_u = " UPDATE PUR1100T      														\n"
				          + " SET    REQ_STATUS    				= ?       ,									\n"
				          + "        UPD_BY      				= ?       , 					            \n"
				          + "        UPD_DATE    				= sysdate									\n"
				          + " WHERE  PAYREQ_ID      			= ?        									\n" ;
				  
				persistent_u.setStatement(sqlstr_u);
				
				persistent_u.addParameter(statusCd);
				persistent_u.addParameter(userId);
				persistent_u.addParameter(payreqId);
				
				WAFLogger.debug(sqlstr_u);
				WAFLogger.debug(persistent_u.getParameters());
				
				persistent_u.execute();
				persistent_u.clearParameters();
				
				String resUserName = params.get("resUserName");			//계약 담당자명
				String resHp = params.get("resHp").replaceAll("-", "");	//계약 담당자 핸드폰번호
				String resEmail = params.get("resEmail");				//계약 담당자 이메일
				String resDivsion = params.get("resDivsion");			//계약 담당자 부서

				String hp = params.get("hp").replaceAll("-", "");	//업체 담당자 핸드폰번호
				String eMail = params.get("eMail");					//업체 담당자 이메일
	        	String memberName = params.get("memberName");		//업체명
	        	String userName = params.get("userName");			//업체 담당자명
	        	String deptName = params.get("deptName");			//현장명
	        	String conDocNo = params.get("conDocNo");			//계약번호
	        	String buildName = params.get("buildName");			//계약명

				//SMS
	        	MessageSend messageSend = new MessageSend(storage);
		      	String recvAddress = hp;
	        	String smsContent = WAFMessages.getMessage("Billing.Application.Request");
	        	
	        	messageSend.sendSMS(recvAddress, storage.getUser().get("USER_PHONE"), storage.getUser().get("ACCT_ID"), smsContent); //2015.9.21 구매 대금신청 설치성 담당자->현업resHp
	        	
	        	//E-Mail
	        	MessageSend mailSend = new MessageSend(storage);
	        	StringBuffer mailContent = new StringBuffer();
	        	mailContent.append(memberName+ "님이 대금을 신청하였습니다. </BR>");
	        	mailContent.append("협력업체포탈시스템에 접속하시어 대금정보 확인후 신청바랍니다. </BR>");
	        	mailContent.append("<font style='width:auto; font-size:12px; line-height:18px; padding:5px; text-align:left;'>");
	        	mailContent.append("</BR>");
	        	mailContent.append("1.프로젝트: "+deptName+"</BR>");
	        	mailContent.append("2.계약번호: "+conDocNo+"</BR>");
	        	mailContent.append("3.계약명: " +buildName+"</BR>");
	        	mailContent.append("4.계약담당자:"+resDivsion+"/"+resUserName+"(연락처 :"+resHp+")</BR>");
	        	mailContent.append("</font>");
	        	WAFLogger.debug("send email before ");
				messageSend.sendEmail(eMail, resEmail, "대금 신청 요청 메일입니다.", "대금 신청 요청 메일입니다.", mailContent);	//(받는주소, 보낸주소, 제목, 소제목, 내용)
				WAFLogger.debug("send email ");
				
				super.storage.setSuccess(true);
			}			
	        catch(Exception e) {
	            super.doException(e);
	            super.storage.setMessage(e.getMessage());
	            super.storage.setDetailMessage(e);
	            super.conn.setRollback();
	        	super.storage.setSuccess(false);
	        }
	        finally {
	        	super.conn.end();
	        }
		}else if(storage.compareEvent("BUDGET_CHECK")){
			
			WAFLogger.debug("BUDGET_CHECK");
    		
			String dept_cd   = params.get("dept_cd");
    		String checkFlag = budgetCheck(dept_cd); 
    		ValueObject vo = new ValueObject();
    		vo.set("checkFlag", checkFlag);
    		storage.addValueObject("VALUEOBJECT", vo);
    		storage.setSuccess(true);
    		
		}else if(storage.compareEvent("GET_BUDGET_AMT")){
			//2018.11.26 예산체크 호출 없음.   	
			WAFLogger.debug("GET_BUDGET_AMT");
			
    		ValueObject budgetAMTVO = new ValueObject();
    		ValueObject checkVO = new ValueObject();
    		String payreq_id = params.get("payreqId");
    		
    		// 선급공제 시 같은 PAYREQ_ID 이므로 중복제거한다.
    		String check_id[] = payreq_id.split(";");
    		ArrayList<String> list = new ArrayList<String>();
    		for(int i=0; i<check_id.length ; i++){
    			if(!list.contains(check_id[i])) list.add(check_id[i]);
    		}
    		String d_check_id[] = new String[list.size()];
    		list.toArray(d_check_id);
    		
    		for(int i=0; i<d_check_id.length ; i++){
    			String enterDt = params.get("date1").replaceFirst("-", "").substring(0, 6);
    			String dept_cd = params.get("dept_cd");
    			String pItem = params.get("pItem");
    			//budgetAMTVO = getBudgetAMT(enterDt, d_check_id[i], dept_cd, pItem);   		
    			if(budgetAMTVO.get("CNT").equals("999")){
    				
	    		}else{
	    			double calFlag = Double.parseDouble(budgetAMTVO.get("CAL_AMT"));
	    			// -금액이 여러건일 경우 마지막 budgetAMTVO 를 저장하여 반환하여 Alert 표기
	    			if(0 > calFlag){
	    				checkVO = budgetAMTVO;
	    			}
	    		}
    		}
    		if(checkVO.size() > 0){
    			budgetAMTVO = checkVO;
    		}
    		
    		storage.addValueObject("VALUEOBJECT", budgetAMTVO);
    		storage.setSuccess(true);
		}else if(storage.compareEvent("SAVE_ATTC")){
			
			//기타서류 첨부파일 조회
			String payreqId					= params.get("payreqId");				//지급신청ID
		    RowSet purchaseFileRow = getfileListRowSet("PURCHASE_"+payreqId, "");
		    
		    String docPayReq 			= "N";	//대금청구서
		    String docMrr				= "N";	//MRR
		    String docIteminputconfirm 	= "N";	//원자재입고확인서
		    String docInspectionReport 	= "N";	//Inspectin Reqport
		    String docConfirm		 	= "N";	//납품확인서
		    String docFinalDocuments	= "N";	//Final Documents 제출확인서
		    String docGuarConst			= "N";	//계약이행보증보험증권
		    String docGuarAs			= "N";	//하자이행보증보험증권
		    String docWorkqa			= "N";	//기성검사보고서
		    String docShip				= "N";	//선적서류
		    String docComplete			= "N";	//준공검사보고서
		    String docConstCopy			= "N";	//계약서사본
		    String docEtc				= "N";	//기타
		    String docTestrun			= "N";	//시운전안전보고서
		    String docMc				= "N";	//M/C
		    String docTaxOrInvoice		= "N";	//TaxOrInvoice

		    for(int i=0; i<purchaseFileRow.size() ; i++){
		    	
		    	Row row = purchaseFileRow.getRow(i);
		    	if(row.get("DOC_CD").equals("110")){	//대금청구서
		    		docPayReq = "Y";
		    	}else if(row.get("DOC_CD").equals("120")){	//계약이행 보증보험 증권
		    		docGuarConst = "Y";
		    	}else if(row.get("DOC_CD").equals("130")){	//지급이행 보증보험 증권
		    		docMrr = "Y";
		    	}else if(row.get("DOC_CD").equals("140")){	//하자이행 보증보험 증권
		    		docGuarAs = "Y";
		    	}else if(row.get("DOC_CD").equals("150")){	//원자재입고확인서
		    		docIteminputconfirm = "Y";
		    	}else if(row.get("DOC_CD").equals("160")){	//MRR
		    		docConfirm = "Y";
		    	}else if(row.get("DOC_CD").equals("170")){	//거래명세표
		    		docWorkqa = "Y";
		    	}else if(row.get("DOC_CD").equals("180")){	//설치완료확인서
		    		docComplete = "Y";
		    	}else if(row.get("DOC_CD").equals("190")){	//시운전안전보고서
		    		docTestrun = "Y";
		    	}else if(row.get("DOC_CD").equals("200")){	//Inspection Report
		    		docInspectionReport = "Y";
		    	}else if(row.get("DOC_CD").equals("210")){	//선적서류
		    		docShip = "Y";
		    	}else if(row.get("DOC_CD").equals("220")){	//Final Documents
		    		docFinalDocuments = "Y";
		    	}else if(row.get("DOC_CD").equals("230")){	//계약서 사본
		    		docConstCopy = "Y";
		    	}else if(row.get("DOC_CD").equals("240")){	//기타
		    		docEtc = "Y";
		    	}else if(row.get("DOC_CD").equals("250")){	//M/C
		    		docMc = "Y";
		    	}else if(row.get("DOC_CD").equals("260")){	//docTax or Invoice
		    		docMc = "Y";
		    	}
		    }
		    
			Persistent persistent_u = null;
			String sqlstr_u = "";

			try {
			
				conn.begin();
				persistent_u = new PersistentImpl(super.conn.getConnection());
				sqlstr_u = " UPDATE PUR1100T      															\n"
				          + " SET    DOC_PAYREQ    				= ?       ,									\n"
				          + "        DOC_GUAR_CONST      		= ?       , 					            \n"
				          + "        DOC_MRR      				= ?       , 					            \n"
				          + "        DOC_GUAR_AS      			= ?       , 					            \n"
				          + "        DOC_ITEMINPUTCONFIRM      	= ?       , 					            \n"
				          + "        DOC_CONFIRM      			= ?       , 					            \n"
				          + "        DOC_WORKQA      			= ?       , 					            \n"
				          + "        DOC_COMPLETE      			= ?       , 					            \n"
				          + "        DOC_TESTRUN      			= ?       , 					            \n"
				          + "        DOC_INSPECTION_REPORT      = ?       , 					            \n"
				          + "        DOC_SHIP      				= ?       , 					            \n"
				          + "        DOC_FINAL_DOCUMENTS      	= ?       , 					            \n"
				          + "        DOC_CONST_COPY      		= ?       , 					            \n"
				          + "        DOC_ETC      				= ?       , 					            \n"
				          + "        DOC_MC      				= ? 	  ,     					        \n"
				          + "        REQ_CHARGE_ID      		= ? 	  ,    					            \n"
				          + "        DOC_TAX_INVOICE			= ? 	       					            \n"
				          + " WHERE  PAYREQ_ID      			= ?        									\n"
				          ;
				  
				persistent_u.setStatement(sqlstr_u);
				
				persistent_u.addParameter(docPayReq);
				persistent_u.addParameter(docGuarConst);
				persistent_u.addParameter(docMrr);
				persistent_u.addParameter(docGuarAs);
				persistent_u.addParameter(docIteminputconfirm);
				persistent_u.addParameter(docConfirm);
				persistent_u.addParameter(docWorkqa);
				persistent_u.addParameter(docComplete);
				persistent_u.addParameter(docTestrun);
				persistent_u.addParameter(docInspectionReport);
				persistent_u.addParameter(docShip);
				persistent_u.addParameter(docFinalDocuments);
				persistent_u.addParameter(docConstCopy);
				persistent_u.addParameter(docEtc);
				persistent_u.addParameter(docMc);
				persistent_u.addParameter(acctId);
				persistent_u.addParameter(docTaxOrInvoice);
				persistent_u.addParameter(payreqId);
				
				WAFLogger.debug(sqlstr_u);
				WAFLogger.debug(persistent_u.getParameters());
				
				persistent_u.execute();
				persistent_u.clearParameters();

				super.storage.setSuccess(true);
			}			
	        catch(Exception e) {
	            super.doException(e);
	            super.storage.setMessage(e.getMessage());
	            super.storage.setDetailMessage(e);
	            super.conn.setRollback();
	        	super.storage.setSuccess(false);
	        }
	        finally {
	        	super.conn.end();
	        }	    
			
		}else if(storage.compareEvent("SAVE_DRAFT")){
			
			String  signClassCd = "paymentapplication";
			//결재 가능여부 확인
			String validation = "";
			validation = iNisDraftable(signClassCd, "PUR1100T", "PAYREQ_ID", params.get("payreqId"));
			super.storage.setSuccess(true);
			super.storage.setMessage(validation);
		
		} else if(storage.compareEvent("GET_ATTACHFILE")){
			
			//첨부파일
			ValueObject AttachFile = getfilelist("PURCHASE_"+params.get("payreqId"),"","AttachFile");
	        storage.addValueObject("VALUEOBJECT", AttachFile);
		
		} else if(storage.compareEvent("CHK_REJECT")){
			
			String resultChk = "1";	//불가
			String status = "";
			
			status = getRejectionCheck();
			
			if(!status.equals("04")){	//결재중
				resultChk = "0";	//가능
			} 
    		ValueObject vo = new ValueObject();
    		vo.set("checkFlag", resultChk);
    		storage.addValueObject("VALUEOBJECT", vo);
    		storage.setSuccess(true);

		} else if (storage.compareEvent("CHK_VP")) {  //2015.3.9 VP추가
			WAFLogger.debug("chk_vp--------------------------");
			Persistent persistent_u = null;
			String sqlstr_u = "";

			try {
			
				conn.begin();
				persistent_u = new PersistentImpl(super.conn.getConnection());
				sqlstr_u = " UPDATE PUR1100T                                \n" 
				          + " SET    REQ_STATUS                 = '03'      \n"
 				          + " WHERE  PAYREQ_ID      			= ?         \n" ;
				  
				persistent_u.setStatement(sqlstr_u);
				persistent_u.addParameter(params.get("payreqId"));
				
				WAFLogger.debug(sqlstr_u);
				
				persistent_u.execute();
				persistent_u.clearParameters();

				super.storage.setSuccess(true);
			}			
	        catch(Exception e) {
	            super.doException(e);
	            super.storage.setMessage(e.getMessage());
	            super.storage.setDetailMessage(e);
	            super.conn.setRollback();
	        	super.storage.setSuccess(false);
	        }
	        finally {
	        	super.conn.end();
	        }	    
		}
		else if(storage.compareEvent("CHK_APPVAR")){
			
			String resultChk = "1";	//불가
			String status = "";
			
			status = getRejectionCheck();
			
			if(!status.equals("04")){	//결재중
				resultChk = "0";	//가능
				
				if("2".equals(params.get("btnAppReqSelect"))){
					status = getTaxOrInvoiceCnt();
					if(!status.equals("99")){
						resultChk = "0";	//
					}else{
						resultChk = "99";	//
					}
				}
			} 
    		ValueObject vo = new ValueObject();
    		vo.set("checkFlag", resultChk);
    		storage.addValueObject("VALUEOBJECT", vo);
    		storage.setSuccess(true);

    		
		} else if(storage.compareEvent("GET_RATE")){
			
			String rateEx = "0";
			String rateAmt = "0";
			String rateVamt = "0";
			String rateDy = params.get("date1").replace("-", "");
			String curGb = params.get("conCurCd");
			String reqPrepaySupplyAmt = params.get("curReqAmt").replace(",", "");
			String inputVat = params.get("bugase");
			
			ValueObject vo = new ValueObject();
			
			if(!"KRW".equals(curGb)){
				
				ValueObject RageExValue = getRageEx(rateDy, curGb, reqPrepaySupplyAmt, inputVat);
				//rateEx = RageExValue.get("RATE");
				//rateAmt = rowObject.get("RATE_AMT");
				//rateVamt = rowObject.get("RATE_VAMT");
				
				vo.set("rate", RageExValue.get("RATE"));
				vo.set("rateAmt", RageExValue.get("RATE_AMT"));
				vo.set("rateVamt", RageExValue.get("RATE_VAMT"));
				
			}else{
	
				vo.set("rate", rateEx);
				vo.set("rateAmt", rateAmt);
				vo.set("rateVamt", rateVamt);
			}
			
    		storage.addValueObject("VALUEOBJECT", vo);
    		storage.setSuccess(true);

		} else if (storage.compareEvent("PLAN_REQ")) {  //2015.3.9 VP추가
			WAFLogger.debug("설계평가요청(메일발송)--------------------------");
			Persistent persistent_u = null;
			String sqlstr_u = "";

			try {
				//대금 신청 상제 정보
				String payreqId					= params.get("payreqId");				//지급신청ID								
				String userId					= storage.getUser().get("ACCT_ID");		//로그인사용자
				
				conn.begin();
				
				persistent_u = new PersistentImpl(super.conn.getConnection());

				sqlstr_u = " UPDATE CONT_PUR_PAYPLAN      														\n"
				          + " SET    PLAN_APPR_SEND_YN			= 'Y'       ,									\n"
				          + "        UPD_BY      				= ?       , 					            \n"
				          + "        UPD_DATE    				= sysdate									\n"
				          + " WHERE  PAYREQ_ID      			= ?        									\n" ;
				  
				persistent_u.setStatement(sqlstr_u);
								
				persistent_u.addParameter(userId);
				persistent_u.addParameter(payreqId);
				
				WAFLogger.debug(sqlstr_u);
				WAFLogger.debug(persistent_u.getParameters());
				
				persistent_u.execute();
				persistent_u.clearParameters();
				
				//E-Mail(설계평가 담당자 메일 발송)	     
				ValueObject planApprInfo = getPlanApprInfo(params);				
				String PLAN_APPR_CHK_EMPNM = planApprInfo.get("PLAN_APPR_CHK_EMPNM");
				String PLAN_APPR_EMAIL = planApprInfo.get("PLAN_APPR_EMAIL");
				String deptName = params.get("deptName");			//현장명
		        String conDocNo = params.get("conDocNo");			//계약번호
		        String buildName = params.get("buildName");			//계약명

		        MessageSend mailSend = new MessageSend(storage);
				StringBuffer mailContent2 = new StringBuffer();
//	        	mailContent2.append(memberName+ "님이 대금을 신청하였습니다. </BR>");
	        	mailContent2.append("전자조달시스템에 접속하시어 설계평가 작성하시기 바랍니다. </BR>");
	        	mailContent2.append("경로 : 대금관리 > 구매대금 > 구매_설계평가 </BR>");
	        	mailContent2.append("<font style='width:auto; font-size:12px; line-height:18px; padding:5px; text-align:left;'>");
	        	mailContent2.append("</BR>");
	        	mailContent2.append("1.프로젝트: "+deptName+"</BR>");
	        	mailContent2.append("2.계약번호: "+conDocNo+"</BR>");
	        	mailContent2.append("3.계약명: " +buildName+"</BR>");
	        	mailContent2.append("4.설계평가자: " +PLAN_APPR_CHK_EMPNM+"</BR>");
	        	mailContent2.append("</font>");
	        	WAFLogger.debug("send email before ");	        	
	        	mailSend.sendEmail(PLAN_APPR_EMAIL, "partner@sgc.co.kr", "구매 설계 평가 작성 요청 메일입니다.", "구매 설계 평가 작성 요청 메일입니다.", mailContent2, "NO_LINK");	//(받는주소, 보낸주소, 제목, 소제목, 내용)
				WAFLogger.debug("send email ");
				
				super.storage.setSuccess(true);
			}
			catch(Exception e) {
	            super.doException(e);
	            super.storage.setMessage(e.getMessage());
	            super.storage.setDetailMessage(e);
	            super.conn.setRollback();
	        	super.storage.setSuccess(false);
	        }
	        finally {
	        	super.conn.end();
	        }	          
		}
		
	}

	/**
	 * 결재 상신 가능 여부를 리턴
	 * @param signClassCd
	 * @param linkTable
	 * @param linkColum
	 * @param linkId
	 * @return 
	 * @throws Exception
	 */
    public static String iNisDraftable(String signClassCd, String linkTable, String linkColum, String linkId) throws Exception{
        Search search = new SearchImpl();        
        RowSet rowSet = null;
        String sqlstr = "";     
        String isDraftable = "0";
        try {

        	sqlstr += " SELECT DECODE(A.ATTR_6, NULL, '1', '2') AS APPR_STATUS 		\n"
        			+ " FROM SIGN001V A,  "+linkTable+" B          					\n"
        			+ " WHERE A.SIGN_INTERFACE_ID = B.APPR_ID       				\n"
        			+ " AND A.SIGN_CLASS_CD = '"+signClassCd+"'   					\n"
        			+ " AND B."+linkColum+" = '"+linkId+"'        					\n"
        			; 
            
        	search.setStatement(sqlstr);

            rowSet = search.execute();
            if( rowSet.size() > 0 ) {
            	isDraftable = rowSet.getRow(0).get("APPR_STATUS");
            }
            
        }
        catch(WAFSQLException se) {
        	WAFLogger.debug("--->SignManager : isDraftable() Error");
            se.printStackTrace(System.out);
            WAFLogger.debug(se.getMessage());
            Logger.err.println("SQL : \n" + se.getStatement());
            Logger.err.println("PARAM : \n" + se.getParameter());
        }
        catch(Exception e) {
            Logger.err.printStackTrace(e);
        }
        finally {
            return isDraftable;
        }
    }
    // 예산통제 현장일 경우 예산, 실적 금액 가져온다
    /**
     * 2018.11.20
     * 이인오
     * 사용안함 경영정보 디비링크 삭제
     
    public ValueObject getBudgetAMT_backup(String yymm, String payreq_id) throws Exception{
    	ValueObject row = new ValueObject();
    	String sqlstr = "";
    	Search search = new SearchImpl();
    	RowSet rowSet = null;
    	
		try {
			 
			 search.setStatement(sqlstr.toString());
	    	 rowSet = search.execute();
	    	 WAFLogger.debug("getBudgetAMT sqlstr :"+sqlstr.toString());
			 
			 if (rowSet.size()>0){
    			row.set("YYYYMM", rowSet.getRow(0).get("YYYYMM"));
    			row.set("DEPT_CD", rowSet.getRow(0).get("DEPT_CD"));
    			row.set("PAYITEM", rowSet.getRow(0).get("PAYITEM"));
    			row.set("ESTAMT", rowSet.getRow(0).get("ESTAMT"));
    			row.set("CUR_AMT", rowSet.getRow(0).get("CUR_AMT"));
    			row.set("REMAINDER_AMT", rowSet.getRow(0).get("REMAINDER_AMT"));
    			row.set("SUPPLY_AMT", rowSet.getRow(0).get("SUPPLY_AMT"));
    			row.set("CAL_AMT", rowSet.getRow(0).get("CAL_AMT"));
    			row.set("ESTDESC", rowSet.getRow(0).get("ESTDESC"));
    			row.set("ORD_DESC", rowSet.getRow(0).get("ORD_DESC"));
            }else{
            	row.set("CNT", "999");
            }
		        
		} catch(Exception e) {
		    WAFLogger.error(this.getClass().getName() + " --> getDigit() : " + e.getMessage());
		    WAFLogger.error(e);
		} finally {
		}
		return row;
    }*/
    // 예산통제 현장인지 체크
    public String budgetCheck(String dept_cd) throws Exception {
    	ValueObject vo = new ValueObject();
    	String sqlstr = "";
    	String count = "";
    	Search search = new SearchImpl();
    	RowSet rowSet = null;
    	
    	try{
    		sqlstr = "		SELECT COUNT(*) AS CNT FROM ETEC_ERPIF.ACZ10100		\n"
    				+"		WHERE BUDGET_YN = 'Y'						\n"
    				+"		AND DEPT_CD = '"+ dept_cd +"'					\n";
    		
    		search.setStatement(sqlstr.toString());
    		WAFLogger.debug("budgetCheck sqlstr :"+sqlstr.toString());
	    	rowSet = search.execute();
	    	if (rowSet.size()>0){
    			vo.set("CHECK_YN", rowSet.getRow(0).get("CNT"));
	    	}
    		count = vo.get("CHECK_YN");
//    		WAFLogger.debug("budgetCheck count :"+count);
    		
    	}catch(Exception e){
			WAFLogger.error(this.getClass().getName() + " --> budgetCheck() : " + e.getMessage());
			WAFLogger.error(e);
			throw e;
		}
    	return count;
    }
	
	
    /**
     * 첨부파일 조회.
	 * @param 
	 * @param 
	 * @return ValueObject
	 */
	private ValueObject getfilelist(String filegb,String id,String returnid){
		ValueObject vo = new ValueObject();
		RowSet rowSet = FileManager.getFileList(filegb, id);
		String str="";
	        for(int i=0;i<rowSet.size();i++){
	        	Row row=rowSet.getRow(i);
	        	str += (i+1)+" : "+row.get("FILE_NAME")+" ("+ row.get("FILE_SIZE")+")";
	        	if(i+1!=rowSet.size()){
	        		str +="\r\n";
	        	}
	        }
	        vo.set(returnid, str);
		return vo;
	}
	
    /**
     * 선급금 신청 신청구분를 조회 한다.
	 * @param 
	 * @param 
	 * @return ValueObject
	 */
	public RowSet getPerpayReqDiv(){

        Search search = new SearchImpl();
        RowSet listRowSet = null;
        String sqlstr = "";
        
        try {
            sqlstr += " SELECT DETAILCD, DETAILNM             	\n"
                    + " FROM EBID_COM911T      					\n"
                    + " WHERE BASECD = 'REG_DIV_CD'     		\n";
             
            search.setStatement(sqlstr);
            listRowSet = search.execute();
			
		}catch(Exception e){
			e.printStackTrace();
		}finally{

			if( listRowSet == null ){
            	listRowSet = new RowSetImpl();
            }
            
			return listRowSet;
		}
	}
	
    /**
     *@param ValueObject
     *@return ValueObject
     *기   능 : 대금신청 상세(구매 중도금,잔금)
     *@author OK
     *@version 2014. 8. 07.
     *@since JDK1.7
     */
    public ValueObject getPayItem(ValueObject Params) {
        Search search = new SearchImpl();
        RowSet listRowSet = null;
        String sqlstr = "";
        ValueObject rowObject = null;
        
        try {

        	sqlstr += " SELECT 			  								  																						\n"
        			+ "     A.PUR_CONT_ID	                			  																						\n"
        			+ "     ,A.DEPT_CD                      --현장코드	 																						\n"
        			+ "     ,F_GET_R_DEPT_CD(A.DEPT_CD) P_DEPT_CD          --현장코드 P158->1631로 변환한 DEPT 2015.10.7                     										\n"
        			+ "     ,A.DEPT_NAME                    --현장명		  																						\n"
        			+ "     ,A.CON_GB                       --계약구문  																							\n"
        			+ "     ,A.ORD_DOC_NO                 	--발주계약번호																						\n"
        			+ "     ,A.CST_DOC_NAME             	--계약명		  																						\n"
        			+ "     ,A.CURRENCY_GB                	--통화		  																						\n"
        			+ "     ,substr(D.CORP_REG_NO,0,3)||'-'||substr(D.CORP_REG_NO,4,2)||'-'||substr(D.CORP_REG_NO,6,5) AS REG_NO       --사업자번호				\n"
        			+ "     ,D.CORP_KOR AS CORP_KOR                     --계약업체명     																			\n"
        			+ "     ,D.REP_NAME AS BOSS_NAME					  																						\n"
        			+ "     ,TO_CHAR(A.ORD_START_DATE, 'YYYY-MM-DD') || ' ~ '|| TO_CHAR(ORD_END_DATE, 'YYYY-MM-DD') AS ORD_START_END_DATE --계약기간				\n"
        			+ "     ,B.ORD_AMT                       --발주계약금액 		  																				\n"
        			+ "     ,B.DEPOSIT_RESN AS DDD     	--대금지불방법														         							\n"
        			+ "     ,NVL(B.TAX_METHOD_CD, '1') AS TAX_METHOD_CD	    --세금계산서 발행방법																	\n"
        			+ "     ,NVL(B.TAX_DY, TO_CHAR(SYSDATE, 'YYYY-MM-DD')) AS TAX_DY   --작성일자				       			  									\n"
        			+ "     ,B.TAX_CHARG_NM			   	--담당자명											      			  									\n"
        			+ "     ,B.TAX_CHARG_HP	    		--담당자 핸드폰번호									       			  									\n"
        			+ "     ,B.TAX_CHARG_EMAIL		 	--담당자 이메일  											   			  									\n"
        			+ "     ,B.PAY_DIV                  --대금구분								                			  									\n"
        			+ "     ,B.DEPOSIT_CD               --지급구분								                			  									\n"
        			+ "     ,B.DEPOSIT_SEQ              --지급차수								                			  									\n"
        			+ "     ,NVL(C.REQ_PREPAY_AMT       ,0) AS PREPAY_AMT    		--선급금 청구금액  합계					               			  			\n"
        			+ "     ,NVL(C.REQ_PREPAY_SUPPLY_AMT,0) AS PREPAY_SUPPLY_AMT   	--선급금 청구금액 청구금액					               			  			\n"
        			+ "     ,NVL(C.REQ_PREPAY_SURTAX_AMT,0) AS PREPAY_SURTAX_AMT    --선급금 청구금액 부가세					               			  			\n"
        			+ "     ,DECODE(B.SUPP_SIGN_DT, null, '미서명', to_char(B.SUPP_SIGN_DT, 'yyyy-mm-dd HH24:MI:SS') ) AS  CUST_SIGN_DATE --서명일시	\n"
					+ "     ,NVL(B.BEF_ACMP_APPLYAMT, 0) AS BEF_ACMP_APPLYAMT          --전회까지 청구금액 공급가액													\n"
					+ "     ,NVL(B.BEF_ACMP_VAT, 0) AS BEF_ACMP_VAT                    --전회까지 청구금액 부가세													\n"
					+ "     ,NVL(B.BEF_ACMP_AMT, 0) AS BEF_ACMP_AMT                    --전회까지 청구금액 합계														\n"
					+ "     ,NVL(B.BEF_ACMP_PERCENT, 0) AS BEF_ACMP_PERCENT            --전회까지 청구금액 지급율													\n"
					+ "     ,NVL(B.CUR_ACMP_APPLYAMT, 0) AS CUR_ACMP_APPLYAMT          --금회 청구금액 공급가액														\n"
					+ "     ,NVL(B.CUR_ACMP_VAT, 0) AS CUR_ACMP_VAT                    --금회 청구금액 부가세														\n"
					+ "     ,NVL(B.CUR_ACMP_AMT, 0) AS  CUR_ACMP_AMT                   --금회 청구금액 합계														\n"
					+ "     ,NVL(B.CUR_ACMP_PERCENT, 0) AS CUR_ACMP_PERCENT            --금회 청구금액 지급율														\n"
					+ "     ,NVL(B.CUR_BEF_ACMP_SUPPLYAMT, 0) AS CUR_BEF_ACMP_SUPPLYAMT	   --누계 청구금액 공급가액													\n"
					+ "     ,NVL(B.CUR_BEF_ACMP_VAT, 0) AS CUR_BEF_ACMP_VAT                --누계 청구금액 부가세													\n"
					+ "     ,NVL(B.CUR_BEF_ACMP_AMT, 0) AS CUR_BEF_ACMP_AMT                --누계 청구금액 합계													\n"
					+ "     ,NVL(B.CUR_BEF_ACMP_PERCENT, 0) AS CUR_BEF_ACMP_PERCENT   	   --누계 청구금액 지급율													\n"
					+ "     ,NVL(B.REMAINDER_ACMP_SUPPLYAMT, 0) AS REMAINDER_ACMP_SUPPLYAMT   --잔여 청구금액 공급가액												\n"
					+ "     ,NVL(B.REMAINDER_ACMP_VAT, 0) AS REMAINDER_ACMP_VAT               --잔여 청구금액 부가세												\n"
					+ "     ,NVL(B.REMAINDER_ACMP_AMT, 0) AS REMAINDER_ACMP_AMT               --잔여 청구금액 합계													\n"
					+ "     ,NVL(B.REMAINDER_ACMP_PERCENT, 0) AS REMAINDER_ACMP_PERCENT       --잔여 청구금액 지급율												\n"
					+ "     ,NVL(B.BEF_PREPAY_APPLYAMT, 0) AS BEF_PREPAY_APPLYAMT             --전회까지 선급금반제 공급가액										\n"
					+ "     ,NVL(B.BEF_PREPAY_VAT, 0) AS BEF_PREPAY_VAT		                  --전회까지 선급금반제 부가세											\n"
					+ "     ,NVL(B.BEF_PREPAY_AMT, 0) AS BEF_PREPAY_AMT                       --전회까지 선급금반제 합계											\n"
					+ "     ,NVL(B.BEF_PREPAY_PERCENT, 0) AS BEF_PREPAY_PERCENT               --전회까지 전급금반제 지급율											\n"
					+ "     ,NVL(B.CUR_PREPAY_APPLYAMT, 0) AS CUR_PREPAY_APPLYAMT             --금회 선급금반제 공급가액											\n"
					+ "     ,NVL(B.CUR_PREPAY_VAT, 0) AS CUR_PREPAY_VAT	                      --금회 선급금반제 부가세												\n"
					+ "     ,NVL(B.CUR_PREPAY_DEDUCTAMT, 0) AS CUR_PREPAY_DEDUCTAMT           --금회 선급금반제 합계												\n"
					+ "     ,NVL(B.CUR_PREPAY_PERCENT, 0) AS CUR_PREPAY_PERCENT               --금회 선급금반제 지급율												\n"
					+ "     ,NVL(B.CUR_BEF_PREPAY_SUPPLYAMT, 0) AS CUR_BEF_PREPAY_SUPPLYAMT   --누계 선급금반제 공급가액											\n"
					+ "     ,NVL(B.CUR_BEF_PREPAY_VAT, 0) AS CUR_BEF_PREPAY_VAT               --누계 선급금반제 부가세												\n"
					+ "     ,NVL(B.CUR_BEF_PREPAY_AMT, 0) AS CUR_BEF_PREPAY_AMT               --누계 선급금반제 합계												\n"
					+ "     ,NVL(B.CUR_BEF_PREPAY_PERCENT, 0) AS CUR_BEF_PREPAY_PERCENT       --누계 선급금반제 지급율												\n"
					+ "     ,NVL(B.REMAINDER_PREPAY_SUPPLYAMT, 0) AS REMAINDER_PREPAY_SUPPLYAMT      --잔여 선급금반제 공급가액										\n"
					+ "     ,NVL(B.REMAINDER_PREPAY_VAT, 0) AS REMAINDER_PREPAY_VAT                  --잔여 선급금반제 부가세										\n"
					+ "     ,NVL(B.REMAINDER_PREPAY_AMT, 0) AS REMAINDER_PREPAY_AMT                  --잔여 선급금반제 합계										\n"
					+ "     ,NVL(B.REMAINDER_PREPAY_PERCENT, 0) AS REMAINDER_PREPAY_PERCENT          --잔여 선급금반제 지급율										\n"
					+ "     ,NVL(B.PAYED_APPLYAMT, 0) AS PAYED_APPLYAMT			                     --전회까지 실지급액 공급가액									\n"
					+ "     ,NVL(B.PAYED_VAT, 0) AS PAYED_VAT					                     --전회까지 실지급액 부가세										\n"
					+ "     ,NVL(B.PAYED_AMT, 0) AS PAYED_AMT				                         --전회까지 실지급액 합계										\n"
					+ "     ,NVL(B.CUR_REQ_AMT, 0) AS CUR_REQ_AMT		                      --금회 실지급액 공급가액												\n"
					+ "     ,NVL(B.CUR_REQ_VATAMT, 0) AS CUR_REQ_VATAMT		                  --금회 실지급액 부가세												\n"
					+ "     ,NVL(B.CUR_REQ_APPLYAMT, 0) AS CUR_REQ_APPLYAMT                   --금회 실지급액 합계													\n"
					+ "     ,NVL(B.CUR_PAYED_SUPPLYAMT, 0) AS CUR_PAYED_SUPPLYAMT             --누계 실지급액 공급가액												\n"
					+ "     ,NVL(B.CUR_PAYED_VAT, 0) AS CUR_PAYED_VAT		                  --누계 실지급액 부가세												\n"
					+ "     ,NVL(B.CUR_PAYED_AMT, 0) AS CUR_PAYED_AMT		                  --누계 실지급액 합계													\n"
					+ "     ,B.PAYREQ_ID               																											\n"
					+ "     ,B.RE_MARKS               																											\n"
					+ "     ,B.REQ_STATUS              																											\n"
					+ "     ,F_GET_CODE_NAME('PURCHASE_STATUS_CD', B.REQ_STATUS) AS STATUS_NM       															\n"
					+ "     ,B.RTN_DATE       																													\n"
					+ "     ,B.RTN_REASON       																												\n"
					+ "     ,B.PUR_CONT_MOD_ID     																												\n"
					+ "     ,D.CORP_ID                                                                													        \n"
					+ "     ,D.CORP_REG_NO                                                                  											        \n"
					+ "     ,(SELECT NVL(CHG_CODE10, 'INPUT_VAT') -- 공급가액의 input_vat : 10% other 0%															\n"
					+ "     FROM EBID_COM911T     																												\n"
					+ "     WHERE BASECD = 'PROOF_CD'   																												\n"
					+ "     AND DETAILCD = NVL(A.GUA_GB, 'Z99')) CHG_CODE10																							\n"
					+ "     ,E.USER_NAME AS RES_USER_NAME																								\n"
					+ "     ,E.DIVISION    AS RES_DIVISION																								\n"
					+ "     ,E.HP              AS RES_HP																								\n"
					+ "     ,E.EMAIL         AS RES_EMAIL																								\n"
					+ "     ,A.DEF_GUAR_AMT_RATE																										\n"
					+ "     ,B.VP_YN																													\n"
					+ "     , F.ARR_ID AS APPR_ARR_ID																									\n"
					+ "     , F.DOC_CD AS APPR_DOC_CD																									\n"
					+ "     , F.APPR_DY AS APPR_DY																												\n"
					+ "     , LENGTH(NVL(F.APPR_NOTE, '')) AS APPR_NOTE	, F.ADM_YEAR 																											\n"
					+ "     ,DECODE(Z1.RTN_REASON, '', '', '기재사항 정정 오류 - ')||Z1.RTN_REASON AS TAX_RTN_REASON																												\n"
					+ "     ,to_char(Z1.RTN_DATE, 'yyyy-mm-dd') AS TAX_RTN_DATE     --반려일자																											\n"

					+ "     ,B.F_TAX_DY AS F_TAX_DY   																							\n"
					+ "     ,B.F_CON_SUPPLY_AMT AS F_CON_SUPPLY_AMT   																						\n"
					
					+ "     ,B.CRE_BY							\n"
					+ "     ,B.UPD_BY							\n"
					+ "     ,NVL(B.SUPP_DIRECT_YN , 'N') AS SUPP_DIRECT_YN						\n"  //2016.6.15 하도급직불 
					+ "     ,NVL(G.CHK6,'A') FOREIGN_CHK					                               \n" 
					+ "     ,DECODE(NVL(G.CHK6,'N'), 'Y', '예', 'N', '아니요') FOREIGN_NM	  				   \n"  //2016.11.10 외환
					+ "     ,NVL(A.ORD_SURTAX_AMT,0) ORD_SURTAX_AMT  	                                    \n"
					+ "     ,NVL(X1.GUAR_YN,'N') GUAR_YN  	                                    \n"//2018.08.06 이행보증 추가 
					+ " FROM PUR2000T A, 																														\n"
        			+ "      PUR1100T B,																														\n"
        			+ "      (SELECT CC.PUR_CONT_ID , SUM(CC.REQ_PREPAY_AMT) AS REQ_PREPAY_AMT,  SUM(CC.REQ_PREPAY_SUPPLY_AMT) AS REQ_PREPAY_SUPPLY_AMT,  SUM(CC.REQ_PREPAY_SURTAX_AMT) AS REQ_PREPAY_SURTAX_AMT  FROM PUR1030T CC WHERE PREPAY_PROC_GB = '10' GROUP BY PUR_CONT_ID) C,																		\n"
        			+ "      SUPP_INFO D          																												\n"
        			+ "      ,cont_pur_supp E          																												\n"
        			+ "      ,BID_FOREIGN_CHK G          				 \n"  //2016.11.10 외국환거래 신고대상 
        			+ "      , (SELECT A.CORP_ID, A.ORD_DOC_NO, A.APPR_TOT_RATE, MAX(A.APPR_DY) APPR_DY, A.ARR_ID, A.DOC_CD, MAX(A.APPR_NOTE) APPR_NOTE  \n"
        			+ "              ,MAX(B.ADM_YEAR) ADM_YEAR 														                              	 \n"
        			+ "          FROM SUPP_APPR A, SUPP_APPR_ITEM B , PUR1100T C						                                                \n"
        			+ "         WHERE A.CORP_ID = B.CORP_ID AND A.ARR_ID = B.ARR_ID AND A.CONT_ID = C.PUR_CONT_ID AND A.DOC_CD IN ('03', '04') AND C.PAYREQ_ID  = '"+ params.get("payreqId") +"'     \n"
        			+ "         GROUP BY A.CORP_ID, A.ORD_DOC_NO, A.APPR_TOT_RATE, A.DOC_CD, A.ARR_ID)  F        			 							\n"
					+ "      ,(SELECT B.PAY_KEY, B.RTN_REASON, B.RTN_DATE          																												\n"
					/**
					 * 2018.11.20
					 * 이인오
					 * 사용안함 경영정보 디비링크삭제
					 */
					+ "      FROM (SELECT PAY_KEY, MIN(TMPSLIP_NO) AS TMPSLIP_NO FROM ETEC_ERPIF.TAX_INT_INFO GROUP BY PAY_KEY) A																											\n"
					+ "      ,ETEC_ERPIF.TAX_INT_INFO B         																												\n"
					+ "      WHERE 1=1          																												\n"
					+ "      AND A.PAY_KEY = B.PAY_KEY        																												\n"
					+ "      AND A.TMPSLIP_NO = B.TMPSLIP_NO        																												\n"
					+ "      ) Z1      																												\n"
					+ "     ,CONT_PUR_PAYPLAN X1			 						\n" //2018.08.06 이행보증 추가 
        			+ " WHERE 1=1																																\n"
        			+ " AND A.PUR_CONT_MOD_ID = B.PUR_CONT_MOD_ID																										\n"
        			+ " AND B.PUR_CONT_ID = C.PUR_CONT_ID(+)																							\n"
        			+ " AND A.CORP_ID = D.CORP_ID																												\n"
        			+ " AND A.pur_cont_mod_id = E.pur_cont_mod_id																												\n"
        			+ " AND  A.ORD_DOC_NO = F.ORD_DOC_NO(+)																												\n"
        			+ " AND A.CORP_ID = F.CORP_ID(+)																												\n"
        			+ " AND B.PAYREQ_ID  = G.BID_DEG(+)	AND G.CHK5(+) = 'P'																											\n"
        			+ " AND E.sign_seq = '2'																												\n"
        			+ " AND Z1.PAY_KEY(+) = B.PAYREQ_ID																												\n"
        			+ " AND B.PUR_CONT_MOD_ID = X1.PUR_CONT_MOD_ID(+)	 					    \n"//2018.08.06 이행보증 추가 
        			+ " AND B.PAYREQ_ID = X1.PAYREQ_ID(+)	 									\n"//2018.08.06 이행보증 추가 
        			;
        	sqlstr += " AND B.PAYREQ_ID = '"+ params.get("payreqId") +"'																					\n"
        			;
        	
            search.setStatement(sqlstr);
            System.out.println("**************");
            System.out.println(sqlstr);
            WAFLogger.debug(sqlstr);
            listRowSet = search.execute();
            rowObject = RowSetUtility.getValueObject(listRowSet.getRow(0));
            
        }
        catch(Exception e) {
            WAFLogger.error(this.getClass().getName() + " --> getPrePayment() : " + e.getMessage());
            WAFLogger.error("SQL : " + search.getStatement());
            WAFLogger.error(e);
            return null;
        }
        finally {

            if( rowObject == null ) rowObject = new ValueObject();
            return rowObject;
        }
    }
 
    /**
     *@param ValueObject
     *@return ValueObject
     *기   능 : 대금신청 상세(구매 중도금,잔금)
     *@author OK
     *@version 2014. 8. 07.
     *@since JDK1.7
     */
    public ValueObject getContInfo(ValueObject Params) {
        Search search = new SearchImpl();
        RowSet listRowSet = null;
        String sqlstr = "";
        ValueObject rowObject = null;
        
        try {

        	sqlstr += " SELECT 			  								  																						\n"
        			+ "     A.PUR_CONT_ID	                			  																						\n"
					+ "     ,B.ACCT_GB       																													\n"
					+ "     ,B.GUA_GB       																													\n"
					+ "     ,B.PAY_GROUP       																													\n"
					+ "     ,B.PAYMENT_TERMS       		 																		                	            \n"
					+ "     ,B.PAY_ITEM ||'-'|| B.COST_CODE ||'-'|| B.COST_TYPE AS PAY_ITEM      																	\n"
					+ "     ,B.PAY_ITEM ||'-'|| B.COST_CODE ||'-'|| B.COST_TYPE ||'(' || F_GET_PAY_ITEM_EST_DESC(B.PAY_ITEM,B.COST_CODE,B.COST_TYPE,A.DEPT_CD)||')' AS PAY_ITEM_NM	      										\n"
					+ "     ,(SELECT AC_UNIT_CD FROM ACZ10100V Z WHERE  Z.DEPT_CD = A.DEPT_CD) AS  AC_UNIT_CD		      										\n"
					+ "     ,B.PAY_ITEM AS P_ITEM  																												\n"
        			+ " FROM PUR1000T A, 																														\n"
//        			+ "      (SELECT B1.*																														\n"
//        			+ "      FROM PUR1100T B1,																													\n"
//        			+ "      (SELECT PUR_CONT_ID, MAX(DEPOSIT_SEQ) AS MAX_DEPOSIT_SEQ FROM PUR1100T GROUP BY PUR_CONT_ID) B2									\n"
//        			+ "      WHERE 1=1																															\n"
//        			+ "      AND B1.PUR_CONT_ID = B2.PUR_CONT_ID																								\n"
//        			+ "      AND B1.DEPOSIT_SEQ = B2.MAX_DEPOSIT_SEQ																							\n"
//        			+ "      ) B, 																																\n"
					+ "      PUR1100T B,																															\n"
        			+ "      PUR1030T C																															\n"
        			+ " WHERE 1=1																																\n"
        			+ " AND A.PUR_CONT_ID = B.PUR_CONT_ID																										\n"
        			//+ " AND A.PUR_CONT_ID = C.PUR_CONT_ID																										\n";
        			+ " AND A.PUR_CONT_ID = C.PUR_CONT_ID(+)																									\n";

        	//sqlstr += " AND A.PUR_CONT_ID = '"+ params.get("purContId") +"'																						\n";
        	sqlstr += " AND B.PAYREQ_ID = '"+ params.get("PAYREQID") +"'																						\n";
        	
            search.setStatement(sqlstr);
            WAFLogger.debug(sqlstr);
            listRowSet = search.execute();
            rowObject = RowSetUtility.getValueObject(listRowSet.getRow(0));
            
        }
        catch(Exception e) {
            WAFLogger.error(this.getClass().getName() + " --> getPrePayment() : " + e.getMessage());
            WAFLogger.error("SQL : " + search.getStatement());
            WAFLogger.error(e);
            return null;
        }
        finally {

            if( rowObject == null ) rowObject = new ValueObject();
            return rowObject;
        }
    }
    
    /**
     *@param ValueObject
     *@return ValueObject
     *기   능 : 대금내역
     *@author OK
     *@version 2014. 8. 07.
     *@since JDK1.7
     */
    public RowSet getPayItemList(String PayItemListId) {
    	Search search = new SearchImpl();
    	RowSet listRowSet = null;
    	String sqlstr = "";
    	
    	try {
    		
    		sqlstr += " SELECT 																											\n"
    				+ "     PAYREQ_ITEM_ID, PAYREQ_ID, STOCK_NO, A.MATERIAL_CD, ITEM_QTY, ITEM_PRI, ITEM_AMT,  GUBUN, EXC_PRI, EXC_AMT,	\n"
    				+ "     B.MATERIAL_NAME AS MATERIAL_NAME,																			\n"
    				+ "     B.MATERIAL_SPEC AS MATERIAL_SPEC,																			\n"
    				+ "     (SELECT DETAILNM FROM EBID_COM911T WHERE BASECD = 'UNIT_KIND_GB' AND DETAILCD = B.UNIT_KIND) AS UNIT_KIND	\n"
    				+ " FROM PMM_PAYREQ_ITEM A, PMM_COMM_MATERIAL_MASTER B								 								\n"
    				+ " WHERE 1=1																										\n"
    				+ " AND A.MATERIAL_CD = B.MATERIAL_CD																				\n"
    				+ " AND PAYREQ_ID = '"+PayItemListId+"'																				\n";
    		
    		search.setStatement(sqlstr);
    		WAFLogger.debug(sqlstr);
    		listRowSet = search.execute();
    		//rowObject = RowSetUtility.getValueObject(listRowSet.getRow(0));
    		
    	}
    	catch(Exception e) {
    		WAFLogger.error(this.getClass().getName() + " --> getPayItemList() : " + e.getMessage());
    		WAFLogger.error("SQL : " + search.getStatement());
    		WAFLogger.error(e);
    		return null;
    	}
    	finally {
    		
    		if( listRowSet == null ) listRowSet = null;
    		return listRowSet;
    	}
    }
    
    /**
     *@param ValueObject
     *@return ValueObject
     *기   능 : 외주계약 보증정보 데이터 조회
     *@author OK
     *@version 2014. 6. 23.
     *@since JDK1.7
     */
    public RowSet getContOutWarr(ValueObject Params) {
        Search search = new SearchImpl();
        RowSet listRowSet = null;
        ValueObject rowObject = null;
        StrBuffer sqlstr = new StrBuffer();
        try {
        	sqlstr.append("	SELECT  WARR_GUBUN	\n");
        	sqlstr.append("	    , WARR_GUBUN_NM	\n");
        	sqlstr.append("	    , MAX(MOD_NO) AS MOD_NO	\n");
        	sqlstr.append("	    , NVL(MAX(WARR_SEQ),(SELECT NVL(MAX(WARR_SEQ),0) + 1 FROM CONT_PUR_WARR WHERE PUR_CONT_MOD_ID = '"+ params.get("selectSubContModId") +"')) AS WARR_SEQ	\n");
        	sqlstr.append("	    , MAX(WARR_WAMT) AS WARR_WAMT	\n");
        	sqlstr.append("	    , MAX(VIEW_DIV) AS VIEW_DIV	\n");
        	sqlstr.append("	    , MAX(CAUSECODE) AS CAUSECODE	\n");
        	sqlstr.append("	    , MAX(CAUSECODE_NM) AS CAUSECODE_NM	\n");
        	sqlstr.append("	    , MAX(GUAR_ORGAN_CODE) AS GUAR_ORGAN_CODE	\n");
        	sqlstr.append("	    , MAX(WARR_GOFFICE_ID) AS WARR_GOFFICE_ID	\n");
        	sqlstr.append("	    , MAX(WARR_GOFFICE) AS WARR_GOFFICE	\n");
        	sqlstr.append("	    , MAX(GUAR_STATUS) AS GUAR_STATUS	\n");
        	sqlstr.append("	    , MAX(GUAR_STATUS_NM) AS GUAR_STATUS_NM	\n");
        	sqlstr.append("	    , MAX(PAPERDATE) AS PAPERDATE	\n");
        	sqlstr.append("	    , MAX(WARR_WGNO) AS WARR_WGNO	\n");
        	sqlstr.append("	    , MAX(WARR_SDATE) AS WARR_SDATE	\n");
        	sqlstr.append("	    , MAX(WARR_EDATE) AS WARR_EDATE	\n");
        	sqlstr.append("	    , MAX(GUAR_ONOFF_NM) AS GUAR_ONOFF_NM	\n");
        	sqlstr.append("	    , MAX(GUAR_ONOFF_YN) AS GUAR_ONOFF_YN	\n");
        	sqlstr.append("	    , MAX(GRTREQNO) AS GRTREQNO	\n");        	
        	sqlstr.append("	     FROM (	\n");
        	
        	if(params.get("depositCD").equals("2")) {	//중도금일경우
            	sqlstr.append("	              SELECT WARR_GUBUN	\n");
            	sqlstr.append("	                   , F_GET_CODE_NAME('GAUR_KIND',WARR_GUBUN) AS WARR_GUBUN_NM	\n");
            	sqlstr.append("	                   , MOD_NO	\n");
            	sqlstr.append("	                   , WARR_SEQ	\n");
            	sqlstr.append("	                   , WARR_WAMT	\n");
            	sqlstr.append("	                   , VIEW_DIV	\n");
            	sqlstr.append("	                   , CAUSECODE	\n");
            	sqlstr.append("	                   , F_GET_CODE_NAME('CAUSECODE',CAUSECODE) AS CAUSECODE_NM	\n");
            	sqlstr.append("	                   , GUAR_ORGAN_CODE	\n");
            	sqlstr.append("	                   , F_GET_CODE_NAME('GUAROFFICEID',GUAR_ORGAN_CODE) AS WARR_GOFFICE_ID	\n");
            	sqlstr.append("	                   , F_GET_CODE_NAME('GUARORGAN',GUAR_ORGAN_CODE) AS WARR_GOFFICE	\n");
            	sqlstr.append("	                   , GUAR_STATUS	\n");
            	sqlstr.append("	                   , F_GET_CODE_NAME('GUAR_STATUS',GUAR_STATUS) AS GUAR_STATUS_NM	\n");
            	sqlstr.append("	                   , PAPERDATE	\n");
            	sqlstr.append("	                   , WARR_WGNO	\n");
            	sqlstr.append("	                   , WARR_SDATE	\n");
            	sqlstr.append("	                   , WARR_EDATE 	\n");
            	sqlstr.append("	                   , DECODE(GUAR_ONOFF_YN,'Y','온라인','N','오프라인') AS GUAR_ONOFF_NM	\n");
            	sqlstr.append("	                   , GUAR_ONOFF_YN 	\n");
            	sqlstr.append("	                   , GRTREQNO 	\n");        	
            	sqlstr.append("	                FROM CONT_PUR_WARR 	\n");
            	sqlstr.append("	               WHERE PUR_CONT_MOD_ID = '"+ params.get("selectSubContModId") +"' 	\n");	//
            	sqlstr.append("	                     AND WARR_GUBUN ='3'	\n");
            	sqlstr.append("	                     AND PAYREQ_ID ='"+ params.get("payreqId") +"'	\n");
            	sqlstr.append("		\n");
            	/*
            	sqlstr.append("	              UNION ALL	\n");
            	sqlstr.append("		\n");
            	sqlstr.append("	              SELECT '3' AS WARR_GUBUN	\n");
            	sqlstr.append("	                   , '선급금보증' AS WARR_GUBUN_NM	\n");
            	sqlstr.append("	                   , B.MOD_NO	\n");
            	sqlstr.append("	                   , NULL AS WARR_SEQ	\n");
            	sqlstr.append("	                   , 0 AS WARR_WAMT	\n");
            	sqlstr.append("	                   , 'PREPAY' AS VIEW_DIV	\n");
            	sqlstr.append("	                   , '13' AS CAUSECODE	\n");
            	sqlstr.append("	                   , F_GET_CODE_NAME('CAUSECODE','13') AS CAUSECODE_NM	\n");
            	sqlstr.append("	                   , '' AS GUAR_ORGAN_CODE	\n");
            	sqlstr.append("	                   , '' AS WARR_GOFFICE_ID	\n");        	
            	sqlstr.append("	                   , '' AS WARR_GOFFICE	\n");
            	sqlstr.append("	                   , '' AS GUAR_STATUS	\n");
            	sqlstr.append("	                   , '' AS GUAR_STATUS_NM	\n");
            	sqlstr.append("	                   , '' AS PAPERDATE	\n");
            	sqlstr.append("	                   , '' AS WARR_WGNO	\n");
            	sqlstr.append("	                   , '' AS WARR_SDATE	\n");
            	sqlstr.append("	                   , '' AS WARR_EDATE 	\n");
            	sqlstr.append("	                   , '' AS GUAR_ONOFF_NM 	\n");
            	sqlstr.append("	                   , '' AS GUAR_ONOFF_YN 	\n");
            	sqlstr.append("	                   , '' AS GRTREQNO 	\n");        	
            	sqlstr.append("	                FROM DUAL A, PUR2000T B, PUR1100T C, CONT_PUR_PAYPLAN  	D  	\n");
            	sqlstr.append("	               WHERE B.PUR_CONT_MOD_ID = C.PUR_CONT_MOD_ID  	\n");
               	sqlstr.append("	               		 AND B.PUR_CONT_MOD_ID = D.PUR_CONT_MOD_ID  	\n");
               	sqlstr.append("	               		 AND D.GUAR_YN = 'Y'  	\n");
               	sqlstr.append("	               		 AND D.PAY_DIV_CD = '02'  	\n");
            	sqlstr.append("	                     AND C.PUR_CONT_MOD_ID = '"+ params.get("selectSubContModId") +"'	\n");
            	sqlstr.append("	                     AND C.CUR_ACMP_AMT > 0	\n");  
            	*/      	        		
        	}else{			//잔금일경우 하자 보여줌
	        	sqlstr.append("	              SELECT WARR_GUBUN	\n");
	        	sqlstr.append("	                   , F_GET_CODE_NAME('GAUR_KIND',WARR_GUBUN) AS WARR_GUBUN_NM	\n");
	        	sqlstr.append("	                   , MOD_NO	\n");
	        	sqlstr.append("	                   , WARR_SEQ	\n");
	        	sqlstr.append("	                   , WARR_WAMT	\n");
	        	sqlstr.append("	                   , VIEW_DIV	\n");
	        	sqlstr.append("	                   , CAUSECODE	\n");
	        	sqlstr.append("	                   , F_GET_CODE_NAME('CAUSECODE',CAUSECODE) AS CAUSECODE_NM	\n");
	        	sqlstr.append("	                   , GUAR_ORGAN_CODE	\n");
	        	sqlstr.append("	                   , F_GET_CODE_NAME('GUAROFFICEID',GUAR_ORGAN_CODE) AS WARR_GOFFICE_ID	\n");
	        	sqlstr.append("	                   , F_GET_CODE_NAME('GUARORGAN',GUAR_ORGAN_CODE) AS WARR_GOFFICE	\n");
	        	sqlstr.append("	                   , GUAR_STATUS	\n");
	        	sqlstr.append("	                   , F_GET_CODE_NAME('GUAR_STATUS',GUAR_STATUS) AS GUAR_STATUS_NM	\n");
	        	sqlstr.append("	                   , PAPERDATE	\n");
	        	sqlstr.append("	                   , WARR_WGNO	\n");
	        	sqlstr.append("	                   , WARR_SDATE	\n");
	        	sqlstr.append("	                   , WARR_EDATE 	\n");
	        	sqlstr.append("	                   , DECODE(GUAR_ONOFF_YN,'Y','온라인','N','오프라인') AS GUAR_ONOFF_NM	\n");
	        	sqlstr.append("	                   , GUAR_ONOFF_YN 	\n");
	        	sqlstr.append("	                   , GRTREQNO 	\n");        	
	        	sqlstr.append("	                FROM CONT_PUR_WARR 	\n");
	        	sqlstr.append("	               WHERE PUR_CONT_MOD_ID = '"+ params.get("selectSubContModId") +"' 	\n");	//
	        	sqlstr.append("	                     AND WARR_GUBUN ='5'	\n");
	        	sqlstr.append("		\n");
	        	sqlstr.append("	              UNION ALL	\n");
	        	sqlstr.append("		\n");
	        	sqlstr.append("	              SELECT '5' AS WARR_GUBUN	\n");
	        	sqlstr.append("	                   , '하자이행보증' AS WARR_GUBUN_NM	\n");
	        	sqlstr.append("	                   , MOD_NO	\n");
	        	sqlstr.append("	                   , NULL AS WARR_SEQ	\n");
	        	sqlstr.append("	                   , 0 AS WARR_WAMT	\n");
	        	sqlstr.append("	                   , 'PAYREQ' AS VIEW_DIV	\n");
	        	sqlstr.append("	                   , '10' AS CAUSECODE	\n");
	        	sqlstr.append("	                   , F_GET_CODE_NAME('CAUSECODE','10') AS CAUSECODE_NM	\n");
	        	sqlstr.append("	                   , '' AS GUAR_ORGAN_CODE	\n");
	        	sqlstr.append("	                   , '' AS WARR_GOFFICE_ID	\n");        	
	        	sqlstr.append("	                   , '' AS WARR_GOFFICE	\n");
	        	sqlstr.append("	                   , '' AS GUAR_STATUS	\n");
	        	sqlstr.append("	                   , '' AS GUAR_STATUS_NM	\n");
	        	sqlstr.append("	                   , '' AS PAPERDATE	\n");
	        	sqlstr.append("	                   , '' AS WARR_WGNO	\n");
	        	sqlstr.append("	                   , '' AS WARR_SDATE	\n");
	        	sqlstr.append("	                   , '' AS WARR_EDATE 	\n");
	        	sqlstr.append("	                   , '' AS GUAR_ONOFF_NM 	\n");
	        	sqlstr.append("	                   , '' AS GUAR_ONOFF_YN 	\n");
	        	sqlstr.append("	                   , '' AS GRTREQNO 	\n");        	
	        	sqlstr.append("	                FROM DUAL A, PUR2000T B  	\n");
	        	sqlstr.append("	               WHERE PUR_CONT_MOD_ID = '"+ params.get("selectSubContModId") +"'	\n");		//"+ params.get("selectSubContModId") +"
	        	sqlstr.append("	                     AND B.DEF_GUAR_AMT > 0	\n");
        	}
        	sqlstr.append("	        )        	\n");
        	sqlstr.append("	GROUP BY  WARR_GUBUN, WARR_GUBUN_NM, CAUSECODE, CAUSECODE_NM	\n");
       	
        	WAFLogger.debug(sqlstr);
            search.setStatement(sqlstr.toString());
            listRowSet = search.execute();           
        }
        catch(Exception e) {
            WAFLogger.error(this.getClass().getName() + " --> getContOutWarr() : " + e.getMessage());
            WAFLogger.error("SQL : " + search.getStatement());
            WAFLogger.error(e);
            return null;
        }
        finally {

            if( rowObject == null ) rowObject = new ValueObject();
        }
        return listRowSet;
    }  

    private String getDigit(RowSet listRowSet, String currencyGB) {
    	ValueObject row = null;
        int size = (listRowSet != null ? listRowSet.size() : 0);

	    if( listRowSet != null && listRowSet.size() > 0) {

            for( int i = 0 ; i < size ; i++ ) {

                row = RowSetUtility.getValueObject(listRowSet.getRow(i));
                
                if (currencyGB.equals((String)row.get("DETAILCD"))) {
                	return (String)row.get("CHG_CODE01");
                }
            }
	    }
	    
	    return "6";
    }
    
	public RowSet getUseCurrencyGBRowSet() {

        Search search = new SearchImpl();
        RowSet rowSet = null;
        String sqlstr = "";
        try {
        	
        	sqlstr += " SELECT DETAILCD, DETAILNM, F_GET_CURRENCY_DIGIT(DETAILCD) CHG_CODE01 FROM EBID_COM911T      	\n"
            		+ " WHERE BASECD = '911'                    														\n"
            		+ " ORDER BY CHG_CODE20                       														\n" ; 
    
            search.setStatement(sqlstr);
            rowSet = search.execute();
        }
        catch(Exception e) {
    
            WAFLogger.error("SQL : " + search.getStatement());
            WAFLogger.error(e);
        }
        finally {
            if( rowSet == null ) rowSet = new RowSetImpl();
            return rowSet;
        }
    }    
    
    /** 첨부서류조회 
     * @return
     * @throws Exception
     */
    public RowSet getfileListRowSet(String payreqId, String code) throws Exception {
        Search search = new SearchImpl();
        RowSet listRowSet = null;
        StringBuffer sql = new StringBuffer();
        try {

    		sql.append("	SELECT distinct A.DETAILCD,								\n");
    		sql.append(" 		   A.DETAILNM,								\n");
    		sql.append(" 		   B.ID AS DOC_CD							\n");
    		sql.append("	FROM EBID_COM911T A, PUB0510T B				\n");
    		sql.append("	WHERE A.BASECD = 'PUR_PAY_FILE'					\n");
    		sql.append("	AND A.DETAILCD = B.ID(+)						\n");
    		//sql.append("	AND A.CHG_CODE01 = '"+code+"'					\n");
    		sql.append("	AND B.FILE_GB(+) = '"+payreqId+"'				\n");
    		//sql.append("	AND DETAILCD NOT IN ('560', '570')				\n");
    		sql.append("	ORDER BY A.DETAILCD								\n");
    		
    		WAFLogger.debug(sql);
        	
            search.setStatement(sql.toString());
            
            listRowSet = search.execute();
            WAFLogger.debug(sql.toString());
            
           
            
        } catch(Exception e) {
            WAFLogger.error(this.getClass().getName() + " --> getListRowSet() : \n" + e.getMessage());
            WAFLogger.error("SQL : " + search.getStatement());
            WAFLogger.error(e);
            
        } finally {
            if( listRowSet == null ) listRowSet = new RowSetImpl();
           
        }
        
        return listRowSet;
    }

    /**
	 * @param 
	 * @param 
	 * @return ValueObject
	 */
	public String  getGubun(){

        Search search = new SearchImpl();
        String resultGubun = "";
        String sqlstr = "";
        String payreqId					= params.get("payreqId");				//지급신청ID	
        
        try {
            sqlstr += " SELECT distinct GUBUN             	\n"
                    + " FROM PMM_PAYREQ_ITEM    			\n"
                    + " WHERE PAYREQ_ID = ? 	     		\n";
             
            search.setStatement(sqlstr);
            search.addParameter(payreqId);
            RowSet listRowSet = search.execute();
            if(listRowSet.size() != 0){
            	ValueObject rowObject = RowSetUtility.getValueObject(listRowSet.getRow(0));
            	resultGubun = rowObject.get("GUBUN");
            }
            
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			return resultGubun;
		}
	}
	
	/**
	 * Persistent 를 이용한 Delete 처리
	 * @param params
	 * @return
     * @throws Exception
	 */
	private boolean delPur1100t() {
		
		
		Persistent persistent_d = null;
		String sqlstr_d = "";

		try {
		
			//선급금 신청 상제 정보
			String payreqId					= params.get("payreqId");				//지급신청ID			
			conn.begin();
			
			persistent_d = new PersistentImpl(super.conn.getConnection());
			
			sqlstr_d = 	" DELETE                   		\n"
		              + " FROM   PUR1100T 				\n"
		              + " WHERE  PAYREQ_ID = ?        	\n";
		        
			persistent_d.setStatement(sqlstr_d);
			persistent_d.addParameter(payreqId);
			
			WAFLogger.debug(sqlstr_d);
			WAFLogger.debug(persistent_d.getParameters());
			
			persistent_d.execute();
			persistent_d.clearParameters();

			return true;
        }
        catch(Exception e) {
            super.doException(e);
            super.storage.setMessage(e.getMessage());
            super.storage.setDetailMessage(e);
            super.conn.setRollback();
            return false;
        }
        finally {
        	super.conn.end();
        }
	}

	/**
	 * Persistent 를 이용한 Delete 처리
	 * @param params
	 * @return
	 * @throws Exception
	 */
	private boolean delPmmPayreqItem() {
		
		
		Persistent persistent_d = null;
		String sqlstr_d = "";
		
		try {
			
			//선급금 신청 상제 정보
			String payreqId					= params.get("payreqId");				//지급신청ID			
			conn.begin();
			
			persistent_d = new PersistentImpl(super.conn.getConnection());
			
			sqlstr_d =" DELETE                   		\n"
					+ " FROM   PMM_PAYREQ_ITEM			\n"
					+ " WHERE  PAYREQ_ID = ?        	\n";
			
			persistent_d.setStatement(sqlstr_d);
			persistent_d.addParameter(payreqId);
			
			WAFLogger.debug(sqlstr_d);
			WAFLogger.debug(persistent_d.getParameters());
			
			persistent_d.execute();
			persistent_d.clearParameters();
			
			return true;
		}
		catch(Exception e) {
			super.doException(e);
			super.storage.setMessage(e.getMessage());
			super.storage.setDetailMessage(e);
			super.conn.setRollback();
			return false;
		}
		finally {
			super.conn.end();
		}
	}
	
	
	
	/**
	 * @param params
	 * @return
	 * @throws Exception
	 */
	private boolean updateContPurPayplan() {
		
		String payreqId					= params.get("payreqId");				//지급신청ID
		
		Search search = new SearchImpl();
		String searchSql = "";
		String resultPurContModId = "";
		String resultPaySeq = "";
		
		Persistent persistent_u = null;
		String sqlstr_u = "";
		
		try {
			
			conn.begin();
			
			persistent_u = new PersistentImpl(super.conn.getConnection());
			sqlstr_u 	= " UPDATE CONT_PUR_PAYPLAN				 				\n"
						+ "    SET PAYREQ_ID = NULL, PAY_YN = 'N'     			\n"
						+ "  WHERE PUR_CONT_MOD_ID = ?        					\n"
						+ "  AND   PAY_SEQ = ?        							\n"
						;
			persistent_u.setStatement(sqlstr_u);
			
			searchSql	+= " SELECT PUR_CONT_MOD_ID, PAY_SEQ             	\n"
						+ "  FROM CONT_PUR_PAYPLAN    						\n"
						+ "  WHERE PAYREQ_ID = ?     						\n";
			
			search.setStatement(searchSql);
			search.addParameter(payreqId);
			WAFLogger.debug(searchSql);
			WAFLogger.debug(search.getParameters());
			RowSet listRowSet = search.execute();
			if(listRowSet.size() != 0){
				for(int i=0; i<listRowSet.size(); i++){
					ValueObject rowObject = RowSetUtility.getValueObject(listRowSet.getRow(i));
					resultPurContModId = rowObject.get("PUR_CONT_MOD_ID");
					resultPaySeq = rowObject.get("PAY_SEQ");
					persistent_u.addParameter(resultPurContModId);
					persistent_u.addParameter(resultPaySeq);
					WAFLogger.debug(sqlstr_u);
					WAFLogger.debug(persistent_u.getParameters());
					persistent_u.execute();
					persistent_u.clearParameters();
				}
			}
			return true;
		}
		catch(Exception e) {
			super.doException(e);
			super.storage.setMessage(e.getMessage());
			super.storage.setDetailMessage(e);
			super.conn.setRollback();
			return false;
		}
		finally {
			super.conn.end();
		}
	}
	
	/**
	 * @param params
	 * @return
	 * @throws Exception
	 */
	private boolean updateWarehouse() {
		
		String payreqId					= params.get("payreqId");				//지급신청ID
		
		Search search = new SearchImpl();
		String searchSql = "";
		String resultWarehouseId = "";
		
		Persistent persistent_u = null;
		String sqlstr_u = "";
		
		try {
			
			conn.begin();
			
			persistent_u = new PersistentImpl(super.conn.getConnection());
			sqlstr_u 	= " UPDATE ETECEPC.FM_WAREHOUSE 					\n"
						+ "    SET RECEIPT_NO = NULL		        		\n"
						+ "  WHERE WAREHOUSE_ID = ?        					\n";
			persistent_u.setStatement(sqlstr_u);
			
			searchSql	+= " SELECT WAREHOUSE_ID			            \n"
						+ "  FROM ETECEPC.FM_WAREHOUSE    				\n"
						+ "  WHERE RECEIPT_NO = ?     					\n";
			
			search.setStatement(searchSql);
			search.addParameter(payreqId);
			WAFLogger.debug(searchSql);
			WAFLogger.debug(search.getParameters());
			RowSet listRowSet = search.execute();
			if(listRowSet.size() != 0){
				for(int i=0; i<listRowSet.size(); i++){
					ValueObject rowObject = RowSetUtility.getValueObject(listRowSet.getRow(i));
					resultWarehouseId = rowObject.get("WAREHOUSE_ID");
					persistent_u.addParameter(resultWarehouseId);
					WAFLogger.debug(sqlstr_u);
					WAFLogger.debug(persistent_u.getParameters());
					persistent_u.execute();
					persistent_u.clearParameters();
				}
			}
			return true;
		}
		catch(Exception e) {
			super.doException(e);
			super.storage.setMessage(e.getMessage());
			super.storage.setDetailMessage(e);
			super.conn.setRollback();
			return false;
		}
		finally {
			super.conn.end();
		}
	}

    // 반려가능상태인지 확인한다.
    public String getRejectionCheck() throws Exception {
    	
        Search search = new SearchImpl();
        RowSet listRowSet = null;
        String sqlstr = "";
        String resultStatus = "";
        ValueObject rowObject = null;
        
        try {

        	sqlstr += " SELECT 			  								  								\n"
					+ "     NVL(B.REQ_STATUS,'00') AS STATUS_CD											\n"
        			+ " FROM PUR1100T B																	\n"
        			+ " WHERE 1=1																		\n"
        			;

        	sqlstr += " AND B.PAYREQ_ID = '"+ params.get("payreqId") +"'								\n"
        			;
        	
            search.setStatement(sqlstr);
            WAFLogger.debug(sqlstr);
            listRowSet = search.execute();
            rowObject = RowSetUtility.getValueObject(listRowSet.getRow(0));
            resultStatus = rowObject.get("STATUS_CD");
        }
        catch(Exception e) {
            WAFLogger.error(this.getClass().getName() + " --> getRejectionCheck() : " + e.getMessage());
            WAFLogger.error("SQL : " + search.getStatement());
            WAFLogger.error(e);
            return null;
        }
        finally {
            
            return resultStatus;
        }
    }
    
    public String getTaxOrInvoiceCnt() throws Exception {
    	
        Search search = new SearchImpl();
        RowSet listRowSet = null;
        String sqlstr = "";
        String resultStatus = "";
        ValueObject rowObject = null;
        
        try {

        	sqlstr += " SELECT 			  								  									\n"
					+ "     DECODE(COUNT(*), 0 , 99, 10) AS  STATUS_CD										\n"
        			+ " FROM EBID_COM911T A, PUB0510T B													\n"
        			+ " WHERE A.BASECD = 'PUR_PAY_FILE'														\n"
        			+ " AND A.DETAILCD = B.ID																\n"
        			+ " AND DETAILCD = '260'																\n"
        			;

        	sqlstr += " AND B.FILE_GB = 'PURCHASE_"+ params.get("payreqId") +"'								\n"
        			;
        	
            search.setStatement(sqlstr);
            WAFLogger.debug(sqlstr);
            listRowSet = search.execute();
            rowObject = RowSetUtility.getValueObject(listRowSet.getRow(0));
            resultStatus = rowObject.get("STATUS_CD");
        }
        catch(Exception e) {
            WAFLogger.error(this.getClass().getName() + " --> getRejectionCheck() : " + e.getMessage());
            WAFLogger.error("SQL : " + search.getStatement());
            WAFLogger.error(e);
            return null;
        }
        finally {
            
            return resultStatus;
        }
    }   
    
    public ValueObject getVendorPrint(ValueObject Params) {
        Search search = new SearchImpl();
        RowSet listRowSet = null;
        StringBuffer sqlStr = new StringBuffer();
        ValueObject rowObject = null;
        
        try {

            sqlStr.append("             SELECT A.DEPT_CD -- 현장코드                                                                            \n");
            sqlStr.append("                          ,DEPT_NAME -- 현장명                                                                            \n");
            sqlStr.append("                          ,CST_DOC_NAME -- 계약명                                                                            \n");
            sqlStr.append("                          ,MEMBER_NAME -- 업체명                                                                            \n");
            sqlStr.append("                          ,VP_DESC -- VP 검토 항목                                                                            \n");
            sqlStr.append("                          ,VP_END_DY                                                                                                     \n");
            sqlStr.append("                          ,DEPOSIT_CD -- 지금구분코드                                                                            \n");
            sqlStr.append("                          ,DEPOSIT_NM -- 지급구분명                                                                            \n");
            sqlStr.append("                          ,DEPOSIT_SEQ -- 지금차수                                                                            \n");
            sqlStr.append("                          ,CURRENCY_GB -- 통화구분                                                                            \n");
            sqlStr.append("                          ,VP_STATUS -- vp 상태                                                                            \n");
            sqlStr.append("                          ,CASE WHEN VP_STATUS = '00' THEN '검토대상'                                                                            \n");
            sqlStr.append("                          WHEN VP_STATUS = '40' THEN 'VP심사중'                                                                            \n");
            sqlStr.append("                          WHEN VP_STATUS = '50' THEN 'VP반려'                                                                            \n");
            sqlStr.append("                          WHEN VP_STATUS = '60' THEN 'VP승인' END VP_STATUS_NM                                                                            \n");
            sqlStr.append("                          ,PAYREQ_ID                                                                            \n");
            sqlStr.append("                          ,SUBSTR(VENDCD, 0,3) || '-' || SUBSTR(VENDCD, 4,2) || '-' || SUBSTR(VENDCD, 6,5) VENDCD --사업자번호                                                                            \n");
            sqlStr.append("                          ,A.BOSS_NAME                                                                            \n");
            sqlStr.append("                          ,ORD_START_END_DATE                                                                            \n");
            sqlStr.append("                          ,ORD_AMT                                                                            \n");
            sqlStr.append("                          ,A.PUR_CONT_MOD_ID                                                                            \n");
            sqlStr.append("                          ,NVL(B.PREPAY_SUPPLY_AMT,0) AS PREPAY_SUPPLY_AMT                                                                            \n");
            sqlStr.append("                          ,'대금지불방법' AS DDD         --대금지불방법                                                                            \n");
            sqlStr.append("                          ,A.PAY_DIV                                                                            \n");
            sqlStr.append("                          ,CUST_SIGN_DATE                                                                            \n");
            sqlStr.append("                          ,A.BEF_ACMP_APPLYAMT                                                                            \n");
            sqlStr.append("                          ,A.BEF_ACMP_VAT                                                                            \n");
            sqlStr.append("                          ,A.BEF_ACMP_AMT                                                                            \n");
            sqlStr.append("                          ,A.BEF_ACMP_PERCENT                                                                            \n");
            sqlStr.append("                          ,FLOOR(CUR_ACMP_APPLYAMT) CUR_ACMP_APPLYAMT -- 금회기성고                                                                            \n");
            sqlStr.append("                          ,CUR_ACMP_VAT                                                                            \n");
            sqlStr.append("                          ,CUR_ACMP_AMT                                                                            \n");
            sqlStr.append("                          ,CUR_ACMP_PERCENT                                                                            \n");
            sqlStr.append("                          ,CUR_BEF_ACMP_SUPPLYAMT                                                                            \n");
            sqlStr.append("                          ,CUR_BEF_ACMP_VAT                                                                            \n");
            sqlStr.append("                          ,CUR_BEF_ACMP_AMT                                                                            \n");
            sqlStr.append("                          ,CUR_BEF_ACMP_PERCENT                                                                            \n");
            sqlStr.append("                          ,REMAINDER_ACMP_SUPPLYAMT                                                                            \n");
            sqlStr.append("                          ,REMAINDER_ACMP_VAT                                                                            \n");
            sqlStr.append("                          ,REMAINDER_ACMP_AMT                                                                            \n");
            sqlStr.append("                          ,REMAINDER_ACMP_PERCENT                                                                            \n");
            sqlStr.append("                          ,VP_CHK_EMPNO --검토자 사                                                                            \n");
            sqlStr.append("                          ,GET_DEPART_DEPT_NAME(VP_CHK_EMPNO) EPART_DEPT_NAME  --검토자 부서                                                                            \n");
            sqlStr.append("                          ,VP_CHK_EMPNM --검토자                                                                            \n");
            sqlStr.append("                          ,VP_CHK_HP --검토자 핸드폰번호                                                                            \n");
            sqlStr.append("                          ,VP_CHK_EMAIL --검토자 EMAIL                                                                            \n");
            sqlStr.append("                          ,VP_RTN_REASON --반려사유                                                                            \n");
            sqlStr.append("                          ,VP_RTN_DY --반려일시                                                                            \n");
            sqlStr.append("                          ,VP_OPINION --VP 의견                                                                            \n");
            sqlStr.append("                          FROM(                                                                            \n");
            sqlStr.append("                          SELECT C.DEPT_CD -- 현장코드                                                                            \n");
            sqlStr.append("                          ,C.DEPT_NAME -- 현장명                                                                            \n");
            sqlStr.append("                          ,C.CST_DOC_NAME -- 계약명                                                                            \n");
            sqlStr.append("                          ,D.MEMBER_NAME -- 업체명                                                                            \n");
            sqlStr.append("                          ,B.VP_DESC -- VP 검토 항목                                                                            \n");
            sqlStr.append("                          ,TO_CHAR(TO_DATE(A.VP_END_DY, 'YYYY-MM-DD'), 'YYYY-MM-DD') VP_END_DY                                                                            \n");
            sqlStr.append("                          ,DEPOSIT_CD -- 지금구분코드                                                                            \n");
            sqlStr.append("                          ,CASE WHEN DEPOSIT_CD = 2 THEN '중도금'                                                                            \n");
            sqlStr.append("                          ELSE '잔금' END DEPOSIT_NM -- 지급구분명                                                                            \n");
            sqlStr.append("                          ,A.DEPOSIT_SEQ -- 지금차수                                                                            \n");
            sqlStr.append("                          ,C.CURRENCY_GB -- 통화구분                                                                            \n");
            sqlStr.append("                          ,CASE WHEN A.REQ_STATUS IN ('00','01','02','03', '05','99') THEN '00'                                                                            \n");
            sqlStr.append("                          WHEN A.REQ_STATUS = '10' THEN '60'                                                                            \n");
            sqlStr.append("                          ELSE A.REQ_STATUS END VP_STATUS -- vp 상태+                                                                            \n");
            sqlStr.append("                          ,A.PAYREQ_ID                                                                            \n");
            sqlStr.append("                          ,D.VENDCD                                                                            \n");
            sqlStr.append("                          ,D.BOSS_NAME                                                                            \n");
            sqlStr.append("                          ,TO_CHAR(C.ORD_START_DATE, 'YYYY-MM-DD') || ' ~ '|| TO_CHAR(C.ORD_END_DATE, 'YYYY-MM-DD') AS ORD_START_END_DATE --계약기간                                                                            \n");
            sqlStr.append("                          ,A.ORD_AMT -- 계약금액                                                                            \n");
            sqlStr.append("                          ,A.PUR_CONT_MOD_ID                                                                            \n");
            sqlStr.append("                          ,DECODE(A.PAY_DIV, '1', '납품정산', '2', '계획분할') PAY_DIV                                                                            \n");
            sqlStr.append("                          ,DECODE(A.SUPP_SIGN_DT, null, '미서명', '서명완료 서명일시 : '||to_char(A.SUPP_SIGN_DT, 'yyyy-mm-dd HH24:MI:SS') ) AS  CUST_SIGN_DATE --서명일시                                                                            \n");
            sqlStr.append("                          ,NVL(A.BEF_ACMP_APPLYAMT, 0) AS BEF_ACMP_APPLYAMT          --전회까지 청구금액 공급가액                                                                            \n");
            sqlStr.append("                          ,NVL(A.BEF_ACMP_VAT, 0) AS BEF_ACMP_VAT                    --전회까지 청구금액 부가세                                                                            \n");
            sqlStr.append("                          ,NVL(A.BEF_ACMP_AMT, 0) AS BEF_ACMP_AMT                    --전회까지 청구금액 합계                                                                            \n");
            sqlStr.append("                          ,NVL(A.BEF_ACMP_PERCENT, 0) AS BEF_ACMP_PERCENT            --전회까지 청구금액 지급율                                                                            \n");
            sqlStr.append("                          ,NVL(A.CUR_ACMP_APPLYAMT, 0) CUR_ACMP_APPLYAMT -- 금회기성고                                                                            \n");
            sqlStr.append("                          ,NVL(A.CUR_ACMP_VAT, 0) CUR_ACMP_VAT -- 금회 청구금액 부가세                                                                            \n");
            sqlStr.append("                          ,NVL(A.CUR_ACMP_AMT, 0) CUR_ACMP_AMT -- 청구금액 합계                                                                            \n");
            sqlStr.append("                          ,NVL(A.CUR_ACMP_PERCENT, 0) CUR_ACMP_PERCENT -- 청구금액 지급율                                                                            \n");
            sqlStr.append("                          ,NVL(A.CUR_BEF_ACMP_SUPPLYAMT, 0) CUR_BEF_ACMP_SUPPLYAMT -- 누계 청구금액 공급가액                                                                            \n");
            sqlStr.append("                          ,NVL(A.CUR_BEF_ACMP_VAT, 0) CUR_BEF_ACMP_VAT -- 누계  청구금액 합계                                                                            \n");
            sqlStr.append("                          ,NVL(A.CUR_BEF_ACMP_AMT, 0) CUR_BEF_ACMP_AMT -- 누계 청구금액 합계                                                                            \n");
            sqlStr.append("                          ,NVL(A.CUR_BEF_ACMP_PERCENT, 0) CUR_BEF_ACMP_PERCENT -- 누계 청구금액 지급율                                                                            \n");
            sqlStr.append("                          ,NVL(A.REMAINDER_ACMP_SUPPLYAMT, 0) AS REMAINDER_ACMP_SUPPLYAMT   --잔여 청구금액 공급가액                                                                            \n");
            sqlStr.append("                          ,NVL(A.REMAINDER_ACMP_VAT, 0) AS REMAINDER_ACMP_VAT   --잔여 청구금액 부가세                                                                            \n");
            sqlStr.append("                          ,NVL(A.REMAINDER_ACMP_AMT, 0) AS REMAINDER_ACMP_AMT   --잔여 청구금액 합계                                                                            \n");
            sqlStr.append("                          ,NVL(A.REMAINDER_ACMP_PERCENT, 0) AS REMAINDER_ACMP_PERCENT   --잔여 청구금액 지급율                                                                            \n");
            sqlStr.append("                          ,NVL(B.VP_CHK_EMPNO, A.VP_CHK_EMPNO) as VP_CHK_EMPNO --검토자 사                                                                            \n");
            sqlStr.append("                          ,NVL(B.VP_CHK_EMPNM , A.VP_CHK_EMPNM)  as VP_CHK_EMPNM --검토자                                                                            \n");
            sqlStr.append("                          ,A.VP_CHK_HP --검토자 핸드폰번호                                                                            \n");
            sqlStr.append("                          ,A.VP_CHK_EMAIL --검토자 EMAIL                                                                            \n");
            sqlStr.append("                          ,A.VP_RTN_REASON --반려사유                                                                            \n");
            sqlStr.append("                          ,TO_CHAR(VP_RTN_DY, 'YYYY-MM-DD') VP_RTN_DY --반려일시                                                                            \n");
            sqlStr.append("                          ,REPLACE(VP_OPINION,CHR(13)||CHR(10),'<br/>')  VP_OPINION -- VP의견                                                                            \n");
            sqlStr.append("                    FROM PUR1100T A                                                                            \n");
            sqlStr.append("                    ,CONT_PUR_PAYPLAN B                                                                            \n");
            sqlStr.append("                    ,PUR2000T C                                                                            \n");
            sqlStr.append("                    ,CONT_PUR_SUPP D                                                                            \n");
            sqlStr.append("                    WHERE A.PAY_DIV = 2                                                                            \n");
            sqlStr.append("                    AND D.SIGN_SEQ = 2                                                                            \n");
            sqlStr.append("                    AND A.PAYREQ_ID = B.PAYREQ_ID                                                                            \n");
            sqlStr.append("                    AND A.PUR_CONT_MOD_ID = C.PUR_CONT_MOD_ID                                                                            \n");
            sqlStr.append("                    AND A.PUR_CONT_MOD_ID = D.PUR_CONT_MOD_ID                                                                            \n");
            sqlStr.append("                    ) A,                                                                            \n");
            sqlStr.append("                    (SELECT CC.* FROM PUR1030T CC WHERE PREPAY_PROC_GB = '10') B                                                                            \n");
            sqlStr.append("                    WHERE A.PUR_CONT_MOD_ID = B.PUR_CONT_MOD_ID(+)                                                                            \n");
            sqlStr.append("                    AND PAYREQ_ID = ?                                                                           \n");
            
            search.setStatement(sqlStr.toString());
            search.addParameter(params.get("payreqId"));
            
            WAFLogger.debug(sqlStr.toString());
            WAFLogger.debug(search.getParameters());
            
            listRowSet = search.execute();
            if( listRowSet != null && listRowSet.size() > 0 ) {
            	rowObject = RowSetUtility.getValueObject(listRowSet.getRow(0));
            }
            
        }
        catch(Exception e) {
            WAFLogger.error(this.getClass().getName() + " --> getPrePayment() : " + e.getMessage());
            WAFLogger.error("SQL : " + search.getStatement());
            WAFLogger.error(e);
            return null;
        }
        finally {

            if( rowObject == null ) rowObject = new ValueObject();
            return rowObject;
        }
    }
    
    public ValueObject getRageEx(String rateDy, String curGb, String reqPrepaySupplyAmt, String inputVat) {
        Search search = new SearchImpl();
        RowSet listRowSet = null;
        String sqlstr = "";
        ValueObject rowObject = null;
        String resultRateEx = "0";
        
        int segumRate = 0;
        if("INPUT_VAT".equals(inputVat)){
        	segumRate = 100 / 10;
        }
        
        try {

        	sqlstr += " SELECT A.RATE																									\n"
        		    + " 	   , A.RATE * TO_NUMBER("+reqPrepaySupplyAmt+") AS RATE_AMT													\n" 
        		    + " 	   , DECODE('"+segumRate+"',0,0,A.RATE * TO_NUMBER("+reqPrepaySupplyAmt+") / "+segumRate+") AS RATE_VAMT								\n" 
					+ " FROM (SELECT F_GET_EXCHANGE_RATE(TO_DATE("+rateDy+", 'YYYYMMDD'), '"+curGb+"', 'KRW') AS RATE FROM DUAL) A			\n"
        			;
        	
            search.setStatement(sqlstr);
            WAFLogger.debug(sqlstr);
            listRowSet = search.execute();
            rowObject = RowSetUtility.getValueObject(listRowSet.getRow(0));
            //resultRateEx = rowObject.get("RATE");
            
        }
        catch(Exception e) {
            WAFLogger.error(this.getClass().getName() + " --> getPrePayment() : " + e.getMessage());
            WAFLogger.error("SQL : " + search.getStatement());
            WAFLogger.error(e);
            return null;
        }
        finally {

            if( rowObject == null ) rowObject = new ValueObject();
            return rowObject;
        }
    }
    //getBudgetAMT() 함수체크 삭제 2018.11.26 ERP 전표생성시 예산확인
    
    public ValueObject getPlanApprInfo(ValueObject Params) {
        Search search = new SearchImpl();
        RowSet listRowSet = null;
        StringBuffer sqlStr = new StringBuffer();
        ValueObject rowObject = null;
        
        try {

            sqlStr.append("             SELECT A.DEPT_CD -- 현장코드                                                                            \n");
            sqlStr.append("                          ,A.DEPT_NAME -- 현장명                                                                            \n");
            sqlStr.append("                          ,A.CST_DOC_NAME -- 계약명                                                                            \n");
            sqlStr.append("                          ,A.MEMBER_NAME -- 업체명                                                                        \n");
            sqlStr.append("                          ,A.CORP_ID -- 업체코드                                                                            \n");
            sqlStr.append("                          ,A.PLAN_APPR_STATUS -- 설계평가 상태                                                                                                        \n");
            sqlStr.append("                          ,A.PAYREQ_ID                                                                             \n");
            sqlStr.append("                          ,A.PLAN_APPR_YN                                                                             \n");
            sqlStr.append("                          ,(SELECT E_MAIL FROM PUB0120T WHERE ACCT_ID = A.PLAN_APPR_CHK_EMPNO AND INACTIVE_DATE IS NULL) AS PLAN_APPR_EMAIL                                                                            \n");            
            sqlStr.append("                          ,A.PLAN_APPR_CHK_EMPNO                                                                             \n");
            sqlStr.append("                          ,A.PLAN_APPR_CHK_EMPNM                                                                             \n");
            sqlStr.append("                          ,A.PLAN_APPR_SEND_YN                                                                             \n");
            sqlStr.append("              FROM(                                                                             \n");
            sqlStr.append("                    SELECT C.DEPT_CD -- 현장코드                                                                             \n");
            sqlStr.append("                          ,C.DEPT_NAME -- 현장명                                                                           \n");
            sqlStr.append("                          ,C.CST_DOC_NAME -- 계약명                                                                           \n");
            sqlStr.append("                          ,D.MEMBER_NAME -- 업체명                                                                           \n");
            sqlStr.append("                          ,D.CORP_ID -- 업체코드                                                                            \n");
            sqlStr.append("                          ,DEPOSIT_CD -- 지금구분코드                                                                           \n");
            sqlStr.append("                          ,B.PLAN_APPR_YN -- 설계평가유무                                                                           \n");
            sqlStr.append("                          ,A.PAYREQ_ID                                                                            \n");
            sqlStr.append("                          ,A.PUR_CONT_ID                                                                            \n");
            sqlStr.append("                          ,C.ORD_DOC_NO                                                                          \n");
            sqlStr.append("                          ,NVL(A.PLAN_APPR_STATUS,'00') AS PLAN_APPR_STATUS -- 설계평가 상태                                                                             \n");
            sqlStr.append("                          ,B.PLAN_APPR_CHK_EMPNO                                                                          \n");
            sqlStr.append("                          ,B.PLAN_APPR_CHK_EMPNM                                                                          \n");
            sqlStr.append("                          ,B.PLAN_APPR_SEND_YN                                                                          \n");
            sqlStr.append("                     FROM PUR1100T A                                                                              \n");
            sqlStr.append("                          ,CONT_PUR_PAYPLAN B                                                                            \n");
            sqlStr.append("                          ,PUR2000T C                                                                            \n");
            sqlStr.append("                          ,CONT_PUR_SUPP D                                                                            \n");
            sqlStr.append("                    WHERE A.PAY_DIV = 2                                                                            \n");
            sqlStr.append("                      AND D.SIGN_SEQ = 2                                                                            \n");
            sqlStr.append("                      AND NVL(B.PLAN_APPR_YN,'N') = 'Y'                                                                            \n");
            sqlStr.append("                      AND A.PAYREQ_ID = B.PAYREQ_ID                                                                           \n");
            sqlStr.append("                      AND A.PUR_CONT_MOD_ID = C.PUR_CONT_MOD_ID                                                                            \n");
            sqlStr.append("                      AND A.PUR_CONT_MOD_ID = D.PUR_CONT_MOD_ID                                                                             \n");
            sqlStr.append("                     )A ,                                                                              \n");
            sqlStr.append("          (SELECT WRITE_NO               \n");
        	sqlStr.append("                , WRITE_NM         \n");
        	sqlStr.append("                , REGU_STATUS_CD         \n");
        	sqlStr.append("                , DOC_CD         \n");
        	sqlStr.append("                , APPR_TOT_RATE         \n");
        	sqlStr.append("                , APPR_NOTE         \n");
        	sqlStr.append("                , DEPT_CD         \n");
        	sqlStr.append("                , CORP_ID         \n");
        	sqlStr.append("                , CONT_ID         \n");
        	sqlStr.append("                , PAYREQ_ID         \n");
        	sqlStr.append("                , ARR_ID         \n");
        	sqlStr.append("                , APPR_DY         \n");
        	sqlStr.append("            FROM SUPP_APPR         \n");
        	sqlStr.append("           WHERE DOC_CD ='06'          \n");        	
        	sqlStr.append("          ) B               \n");
            sqlStr.append("               WHERE 1=1                                                                           \n");
            sqlStr.append("                 AND A.DEPT_CD = B.DEPT_CD(+)                                                                            \n");
            sqlStr.append("                 AND A.CORP_ID = B.CORP_ID(+)                                                                            \n");
            sqlStr.append("                 AND A.PAYREQ_ID = B.PAYREQ_ID(+)                                                                           \n");            
            sqlStr.append("                 AND A.PAYREQ_ID = ?                                                                             \n");
            
            search.setStatement(sqlStr.toString());
            search.addParameter(params.get("payreqId"));
            
            WAFLogger.debug("~~~~~!!!~~~~~~!");
            WAFLogger.debug(sqlStr.toString());
            WAFLogger.debug(search.getParameters());
            
            listRowSet = search.execute();
            if( listRowSet != null && listRowSet.size() > 0 ) {
            	rowObject = RowSetUtility.getValueObject(listRowSet.getRow(0));
            }
            
        }
        catch(Exception e) {
            WAFLogger.error(this.getClass().getName() + " --> getPlanApprInfo() : " + e.getMessage());
            WAFLogger.error("SQL : " + search.getStatement());
            WAFLogger.error(e);
            return null;
        }
        finally {

            if( rowObject == null ) rowObject = new ValueObject();
            return rowObject;
        }
    }
}
