/**
 *
 * @(#)author  [ok]
 * @(#)version 1.0
 * @(#)date    2014. 06. 18
 * @(#)since   JDK 1.7.2
 *
 * Copyright (c) www.udapsoft.co.kr, Inc.
 * All rights reserved.
 * This software is the proprietary information of udapsoft, Inc.
 */
 package kr.co.udapsoft.ebid.buyer.payment.outside.biz;


import kr.co.hsnc.common.base.WAFLogger;
import kr.co.hsnc.common.sql.Row;
import kr.co.hsnc.common.sql.RowSet;
import kr.co.hsnc.common.sql.RowSetImpl;
import kr.co.hsnc.common.sql.search.Search;
import kr.co.hsnc.common.sql.search.SearchImpl;
import kr.co.hsnc.common.sql.util.RowSetUtility;
import kr.co.hsnc.common.util.ValueObject;
import kr.co.udapsoft.ebid.buyer.common.file.FileManager;
import oracle.toplink.internal.ox.StrBuffer;

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

public class AdvencePaymentInitBiz extends Biz {
	
	public AdvencePaymentInitBiz(HandlerStorage storage) {
		super(storage);
	}

	public void doBiz() throws Exception {

		WAFLogger.debug("대금관리.외주대금.선급금관리 상세 페이지 INIT");
		WAFLogger.debug(params.get("selectSubContModId"));
		
		//신청구분ComboList
		RowSet rowSet = getPerpayReqDiv();
		storage.addRowSet("perpayReqDivComboList", rowSet);
		
		//기본 정보, 세금계산서 정보,선급금  
		ValueObject prePayment = getPrePayment(params);
		//환률기준일자
		String rateDy = prePayment.get("TAX_DY");
		String reqPrepaySupplyAmt = prePayment.get("REQ_PREPAY_SUPPLY_TAMT");
		String inputVat = prePayment.get("CHG_CODE10");

		//분계유형
		ValueObject contInfo = getContInfo(params);
        storage.addValueObject("ContInfo", contInfo);

        //계약통화
		String curGb =  prePayment.get("CON_CUR_CD");
		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);
		
		//첨부파일
        storage.addValueObject("SUPP_PREPAYMENTS_GIVEUP", getfilelist("SUPP_PREPAYMENTS_GIVEUP",prePayment.get("PREPAY_ID"),"SUPP_PREPAYMENTS_GIVEUP"));
        storage.addValueObject("SUPP_TAX_BILL", getfilelist("SUPP_TAX_BILL",prePayment.get("PREPAY_ID"),"SUPP_TAX_BILL"));

		//보증정보
        RowSet contOutWarr = getContOutWarr(params);
		storage.addRowSet("contOutWarr", contOutWarr);
		
 	    // 각국 통화코드에 따른 소숫점 이하 자릿수 구하기
        RowSet rowSetGb = getUseCurrencyGBRowSet();
        storage.addRowSet("digitRowSet", rowSetGb);  
        
        // 계약통화 자릿수 구하기
        String digit = getDigit(rowSetGb, (String)prePayment.get("CON_CUR_CD"));
        prePayment.set("digit", digit);
        
		storage.addValueObject("prePayment", prePayment);
		
	}
	
    /**
     * 첨부파일 조회.
	 * @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. 6. 23.
     *@since JDK1.7
     */
    public ValueObject getPrePayment(ValueObject Params) {
        Search search = new SearchImpl();
        RowSet listRowSet = null;
        String sqlstr = "";
        ValueObject rowObject = null;
        
        try {

        	sqlstr += " SELECT 			  								  																						\n"
        			+ "     A1.SUB_CONT_MOD_ID,                			  																						\n"
        			+ "     A1.CON_DOC_NO,	                			  																						\n"
        			+ "     A1.MOD_NO,		                			  																						\n"
        			+ "     A1.SUB_CONT_ID,	                			  																						\n"
        			+ "     A1.MOD_GB,		                			  																						\n"
        			+ "     F_GET_R_DEPT_CD(A1.DEPT_CD) DEPT_CD,		--2015.11.5 P코드 본코드로 대체         											                \n"
        			+ "     A1.DEPT_NAME,              --현장명			  																						\n"
        			+ "     A1.BUILD_NAME,             --계약명			  																						\n"
        			+ "     A1.CON_CUR_CD,             --계약통화			  																						\n"
        			+ "     C1.CORP_REG_NO,            --사업자번호		  																						\n"
        			+ "     C1.CORP_KOR,               --계약업체명	  																							\n"
        			+ "     C1.BOSS_NAME,	           --대표이사 		  																						\n"
        			+ "     TO_CHAR(A1.START_WORK_DATE, 'YYYY-MM-DD') || ' ~ ' || TO_CHAR(A1.END_WORK_DATE, 'YYYY-MM-DD') AS START_END_WORK_DATE,				\n"
        			+ "     A1.CON_AMT,                --계약금									                			  									\n"
        			+ "     A1.CON_SUPPLY_AMT,         --계약공급가  									              			  									\n"
        			+ "     B1.PREPAY_SUPPLY_AMT,      --계약선급공급가 								              			  									\n"
        			+ "     NVL(A1.CON_SUPPLY_TAMT, 0) AS CON_SUPPLY_TAMT,    	   --계약금 과세								         							\n"
        			+ "     NVL(A1.CON_SUPPLY_NAMT, 0) AS CON_SUPPLY_NAMT,   	   --계약금 면세 																	\n"
        			+ "     A1.CON_SURTAX_AMT,         --계약 부가세								                			  									\n"
        			+ "     NVL(B1.PREPAY_AMT, A1.PREPAY_AMT) AS PREPAY_AMT,    --선급금액		                			  									\n"
        			+ "     NVL(B1.PREPAY_SUPPLY_TAMT, NVL(A1.PREPAY_SUPPLY_TAMT, 0)) AS SUB_PREPAY_SUPPLY_TAMT,  --선금금액 과세		  							\n"
        			+ "     NVL(B1.PREPAY_SUPPLY_NAMT, NVL(A1.PREPAY_SUPPLY_NAMT, 0)) AS SUB_PREPAY_SUPPLY_NAMT,  --선금금액 면세  								\n"
        			+ "     NVL(B1.PREPAY_SURTAX_AMT, NVL(A1.PREPAY_SURTAX_AMT, 0)) AS SUB_PREPAY_SURTAX_AMT,     --선급금액 부가세    							\n"
        			//+ "     TO_CHAR(ROUND((A1.PREPAY_AMT / A1.CON_AMT) * 100, 2), 'FM990.00') AS  PREPAY_AMT_PERCENT,    --선급금 요율								\n"
        			+ "     TO_CHAR(ROUND((NVL(B1.PREPAY_SUPPLY_TAMT, NVL(A1.PREPAY_SUPPLY_TAMT, 0))  + NVL(B1.PREPAY_SUPPLY_NAMT, NVL(A1.PREPAY_SUPPLY_NAMT, 0))) / (NVL(A1.CON_SUPPLY_TAMT, 0)  + NVL(A1.CON_SUPPLY_NAMT, 0) )  * 100, 2), 'FM990.00') AS  PREPAY_AMT_PERCENT,    --선급금 요율		\n"
        			+ "     NVL(B1.REQ_PREPAY_AMT, 0) AS REQ_PREPAY_AMT, --선급 신청금액					           			  									\n"
        			+ "     NVL(B1.REQ_PREPAY_SUPPLY_TAMT, 0) AS REQ_PREPAY_SUPPLY_TAMT,    --신청금액_과세	       			  									\n"
        			+ "     NVL(B1.REQ_PREPAY_SUPPLY_NAMT, 0) AS REQ_PREPAY_SUPPLY_NAMT,    --신청금액_면세	      			  									\n"
        			+ "     NVL(B1.REQ_PREPAY_SURTAX_AMT, 0) AS REQ_PREPAY_SURTAX_AMT,      --신청금액_부가세          			  									\n"
        			//+ "     TO_CHAR(ROUND((NVL(B1.REQ_PREPAY_AMT, 0) / A1.CON_AMT) * 100, 2), 'FM990.00') AS REQ_PREPAY_PERCENT,							\n"
        			+ "     TO_CHAR(ROUND((NVL(B1.REQ_PREPAY_SUPPLY_TAMT, 0) + NVL(B1.REQ_PREPAY_SUPPLY_NAMT, 0)) / (NVL(A1.CON_SUPPLY_TAMT, 0)  + NVL(A1.CON_SUPPLY_NAMT, 0) )* 100, 2), 'FM990.00') AS REQ_PREPAY_PERCENT,						\n"
        			+ "     NVL(B1.PREPAY_AMT, 0) - NVL(B1.REQ_PREPAY_AMT, 0) AS GIVE_AMT,   --선급 포기금액 합계     			  									\n"
        			+ "     NVL(B1.PREPAY_SUPPLY_TAMT, 0) - NVL(B1.REQ_PREPAY_SUPPLY_TAMT, 0) AS GIVE_SUPPLY_TAMT,  --선급 포기금액_과세							\n"
        			+ "     NVL(B1.PREPAY_SUPPLY_NAMT, 0) - NVL(B1.REQ_PREPAY_SUPPLY_NAMT, 0) AS GIVE_SUPPLY_NAMT,  --선급 포기금액_면세							\n"
        			+ "     NVL(B1.PREPAY_SURTAX_AMT, 0) - NVL(B1.REQ_PREPAY_SURTAX_AMT, 0) AS GIVE_SURTAX_AMT,     --선급 포기금액_부가세							\n"
        			+ "     TO_CHAR(ROUND(((NVL(A1.PREPAY_AMT, 0) - NVL(B1.REQ_PREPAY_AMT, 0)) / A1.CON_AMT) * 100, 2), 'FM990.00') AS GIVE_PERCENT,				\n"
        			+ "     B1.PREPAY_ID,       --선급ID											                			  									\n"
        			+ "     B1.STATUS_CD,       --선급상태										                			  									\n"
        			+ "     F_GET_CODE_NAME('PREPAY_STATUS_CD', B1.STATUS_CD) AS STATUS_NM,          --선급상태명           			  							\n"
        			+ "     C1.CON_CORP_ID,  --계약업체ID											                			  									\n"
        			+ "     NVL(B1.TAX_METHOD_CD, '1') AS TAX_METHOD_CD,                --발행방법		    	  			  									\n"
        			+ "     NVL(B1.TAX_DY, TO_CHAR(SYSDATE, 'YYYY-MM-DD')) AS TAX_DY,   --작성일자	              			  									\n"
        			+ "     B1.TAX_CHARG_NM AS USER_NAME,   --담당자명										      			  									\n"
        			+ "     B1.TAX_CHARG_HP AS HP,    		--담당자 핸드폰번호								       			  									\n"
        			+ "     B1.TAX_CHARG_EMAIL AS EMAIL, 	--담당자 이메일  										   			  									\n"
        			+ "     NVL(B1.REQ_DIV_CD, '1') AS REQ_DIV_CD,   --신청구분					                			  									\n"
        			+ "     DECODE(B1.SIGN_DT, null, '미서명', to_char(B1.SIGN_DT, 'yyyy-mm-dd HH24:MI:SS') ) AS  CUST_SIGN_DATE,     --서명일시		\n"
        			+ "     B1.RTN_REASON,		--반려사유																										\n"
        			+ "     to_char(to_date(B1.RTN_DATE, 'yyyymmdd'), 'yyyy-mm-dd') AS RTN_DATE     --반려일자													\n"
        			+ "     ,D1.USER_NAME  AS RES_USER_NAME													\n"
        			+ "     ,D1.HP AS RES_HP													\n"
        			+ "     ,D1.EMAIL AS RES_EMAIL													\n"
        			+ "     ,D1.DIVISION AS RES_DIVISION													\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(A1.PROOF_CD, 'Z99')) CHG_CODE10																						\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"
					+ "     ,B1.CRE_BY							\n"
					+ "     ,B1.UPD_BY							\n"
					+ "     ,NVL(G.CHK6,'A') FOREIGN_CHK					                               \n" 
					+ "     ,DECODE(NVL(G.CHK6,'N'), 'Y', '예', 'N', '아니요') FOREIGN_NM	  				   \n"  //2017.02.27 외환
					+ " FROM 																																	\n"
        			+ "       SUB2000T A1,																														\n"
        			+ "       SUB1030T B1,																														\n"
        			+ "       SUB1020T C1,																														\n"
        			+ "       cont_out_supp D1,																														\n"
        			+ "       BID_FOREIGN_CHK G,          				 \n"  //2017.02.27 외국환거래 신고대상 
        			+ "      (SELECT B.PAY_KEY, B.RTN_REASON, B.RTN_DATE																		\n"
					+ "      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"
        			+ " WHERE A1.SUB_CONT_MOD_ID = B1.SUB_CONT_MOD_ID																							\n"
        			+ " AND B1.CON_CORP_ID = C1.CON_CORP_ID(+)																									\n"
        			+ " AND A1.SUB_CONT_MOD_ID = D1.SUB_CONT_MOD_ID																									\n"
        			+ " AND D1.sign_seq = '1'              																								\n"
        			+ " AND A1.CON_CLS_YN = '9'																													\n"
        			+ " AND B1.PREPAY_ID  = G.BID_DEG(+)	AND G.CHK5(+) = 'Q'																											\n"
        			+ " AND Z1.PAY_KEY(+) = B1.PREPAY_ID																												\n"
        			;

        	sqlstr += " AND A1.SUB_CONT_MOD_ID = '"+ params.get("selectSubContModId") +"'																		\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. 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_OUT_WARR WHERE SUB_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");
        	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_OUT_WARR 	\n");
        	sqlstr.append("	               WHERE SUB_CONT_MOD_ID = '"+ params.get("selectSubContModId") +"' 	\n");
        	sqlstr.append("	                     AND WARR_GUBUN IN ('3')	\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("	                   , '11' AS CAUSECODE	\n");
        	sqlstr.append("	                   , F_GET_CODE_NAME('CAUSECODE','11') 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, SUB2000T B, SUB1030T C  	\n");
        	sqlstr.append("	               WHERE B.SUB_CONT_MOD_ID = C.SUB_CONT_MOD_ID  	\n");
        	sqlstr.append("	                     AND B.SUB_CONT_MOD_ID = '"+ params.get("selectSubContModId") +"'	\n");
        	sqlstr.append("	                     AND C.REQ_PREPAY_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;
        }
    }    
    
    public ValueObject getContInfo(ValueObject Params) {
        Search search = new SearchImpl();
        RowSet listRowSet = null;
        String sqlstr = "";
        ValueObject rowObject = null;
        
        try {

        	sqlstr += " SELECT 			  								  																															\n"
        			+ "     A1.SUB_CONT_ID 																																							\n"
					+ "     ,A1.ACCT_GB       																																						\n"
					+ "     ,A1.PROOF_CD      AS GUA_GB																																				\n"
					+ "     ,A1.PAY_GROUP       																													\n"
					+ "     ,A1.PAYMENT_TERMS       																												\n"
					+ "     ,A1.PAY_ITEM ||'-'|| A1.COST_CODE ||'-'|| A1.COST_TYPE AS PAY_ITEM      																	\n"
					+ "     ,A1.PAY_ITEM ||'-'|| A1.COST_CODE ||'-'|| A1.COST_TYPE ||'(' || F_GET_PAY_ITEM_EST_DESC(A1.PAY_ITEM,A1.COST_CODE,A1.COST_TYPE,A1.DEPT_CD)||')' AS PAY_ITEM_NM	      										\n"
					+ "     ,(SELECT AC_UNIT_CD FROM ACZ10100V Z WHERE  Z.DEPT_CD = A1.DEPT_CD) AS  AC_UNIT_CD		      										\n"
        			+ " FROM 																														\n"
        			+ "      SUB2000T A1,																													\n"
        			+ "      SUB1030T B1																													\n"
        			+ " WHERE A1.SUB_CONT_MOD_ID = B1.SUB_CONT_MOD_ID																						\n"
        			+ " AND A1.CON_CLS_YN = '9'																														\n"
        			;
        	
        	sqlstr += " AND A1.SUB_CONT_MOD_ID = '"+ params.get("selectSubContModId") +"'																						\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;
        }
    }
    
    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+"), '"+curGb+"', 'KRW') AS RATE FROM DUAL) A			\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;
        }
    }
    
}
