/**
 *
 * @(#)author  [ok]
 * @(#)version 1.0
 * @(#)date    2014. 06. 26
 * @(#)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.supplier.portal.payment.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.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.ebid.buyer.common.file.FileManager;

import com.udapsoft.modular.web.ibsheet7.IBSheet7Factory;
import com.udapsoft.waf.system.Biz;
import com.udapsoft.waf.system.HandlerStorage;

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

	public void doBiz() throws Exception {

		//System.out.println("협력업체포탈 보증정보 팝업 하자이행보증 정보 INIT");
		////System.out.println(params.get("subContId"));
		//System.out.println(params.get("subContModId"));
		//System.out.println(params.get("warrGubun"));
		//System.out.println(params.get("warrSeq"));
		//System.out.println(params.get("viewOnly"));
		
		//보증기관명 ComboList
		RowSet rowSet = getWarrGofficeList();
		storage.addRowSet("WarrGofficeComboList", rowSet);
		
		//발행구분
		ValueObject WarrGubunNm = getWarrGubun();
		storage.addValueObject("WarrGubunNm", WarrGubunNm);
		
		//보증정보
		ValueObject contOutWarr = getContOutWarr(params);
		storage.addValueObject("contOutWarr", contOutWarr);

		//첨부파일
		storage.addValueObject(params.get("warrGubun"), getfilelist(params.get("warrGubun"),params.get("subContModId"),params.get("warrGubun")));
		
	}

    /**
     * 첨부파일 조회.
	 * @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 ValueObject
     *@return ValueObject
     *기   능 : 외주계약 보증정보 데이터 조회
     *@author OK
     *@version 2014. 6. 23.
     *@since JDK1.7
     */
    public ValueObject getContOutWarr(ValueObject Params) {
        Search search = new SearchImpl();
        RowSet listRowSet = null;
        String sqlstr = "";
        ValueObject rowObject = null;
        
        try {
        	
        	sqlstr += " SELECT                              \n"
    				+ "    SUB_CONT_MOD_ID,                     \n"
    				+ "    WARR_GUBUN,                      \n"
    				+ "    WARR_SEQ,                        \n"
    				+ "    WARR_WAMT,                       \n"
    				+ "    WARR_WRATE,                      \n"
    				+ "    WARR_KAMT1,                      \n"
    				+ "    WARR_KAMT2,                      \n"
    				+ "    WARR_COMMSN,                     \n"
    				+ "    WARR_KCLS,                       \n"
    				+ "    WARR_SDATE,                      \n"
    				+ "    WARR_EDATE,                      \n"
    				+ "    WARR_SDATE ||'~'|| WARR_EDATE AS WARR_SDATE_EDATE,                \n"
    				+ "    WARR_WGNO,                       \n"
    				+ "    WARR_GOFFICE,                    \n"
    				+ "    WARR_GJIJUM,                     \n"
    				+ "    WARR_GTEL,                       \n"
    				+ "    WARR_GMAN,                       \n"
    				+ "    WARR_HEADCONF,                   \n"
    				+ "    WARR_GREM,                       \n"
    				+ "    WARR_INDAY,                      \n"
    				+ "    WARR_INUSR,                      \n"
    				+ "    WARR_UPDAY,                      \n"
    				+ "    WARR_UPUSR,                      \n"
    				+ "    GUAR_ONOFF_YN,                   \n"
    				+ "    GUAR_ORGAN_CODE,                 \n"
    				+ "    CAUSECODE,                       \n"
    				+ "    PAPERDATE,                       \n"
    				+ "    REJECTMENT,                      \n"
    				+ "    EXEMPTMENT,                      \n"
    				+ "    ACCDOCSTATUS,                    \n"
    				+ "    ACCDOC_SEQ,                      \n"
    				+ "    GRTREQNO,                        \n"
    				+ "    YEARINSUREYN,                    \n"
    				+ "    REQDATE,                         \n"
    				+ "    GUAR_STATUS,                     \n"
    				+ "    BOND_SEQ,                        \n"
    				+ "    CONTSEQ,                         \n"
    				+ "    GUARRATEGBNCODE,                 \n"
    				+ "    LONGGBN,                         \n"
    				+ "    ORDEROWNER,                      \n"
    				+ "    CONTAMT,                         \n"
    				+ "    CONTDATE,                        \n"
    				+ "    CONTSTARTDATE,                   \n"
    				+ "    CONTCLOSEDATE,                   \n"
    				+ "    PREPAYREFYN,                     \n"
    				+ "    EXIISTREFYN,                     \n"
    				+ "    TRADESIGNYN,                     \n"
    				+ "    TRADESIGNDATE,                   \n"
    				+ "    CONTCHECKDATE,                   \n"
    				+ "    CONTEXISTENCEAMT,                \n"
    				+ "    PJTID,                           \n"
    				+ "    PAYMETHOD,                       \n"
    				+ "    CONTORGBNCODE,                   \n"
    				+ "    GUAR_CONTAMT,                    \n"
    				+ "    FILETITLE,                       \n"
    				+ "    FILE_NAME,                       \n"
    				+ "    FILEEXT,                         \n"
    				+ "    FILESIZE,                        \n"
    				+ "    EXFILETITLE,                     \n"
    				+ "    EXFILENAME,                      \n"
    				+ "    DEPNM,                           \n"
    				+ "    POSITION,                        \n"
    				+ "    EMPNM,                           \n"
    				+ "    HPNO,                            \n"
    				+ "    TELNO,                           \n"
    				+ "    EMAIL,                           \n"
    				+ "    ITEMDOC,                         \n"
    				+ "    ITEMEXT,                         \n"
    				+ "    ITEMPATH,                        \n"
    				+ "    CONTORDERNO                      \n"
    				+ " FROM CONT_OUT_WARR                  \n"
    				+ " WHERE 1=1			                \n";
        	
        	sqlstr += " AND SUB_CONT_MOD_ID = '"+ params.get("subContModId") +"'	\n";
        	sqlstr += " AND WARR_GUBUN = '"+ params.get("warrGubun") +"'	\n";
        	sqlstr += " AND WARR_SEQ = '"+ params.get("warrSeq") +"'	\n";
        	
            search.setStatement(sqlstr);
            //System.out.println(sqlstr);
            listRowSet = search.execute();
            if(listRowSet.size() != 0){
            	rowObject = RowSetUtility.getValueObject(listRowSet.getRow(0));
            }
            
        }
        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 rowObject;
        }
    }  

    /**
     * 보증기관을 조회한다.
	 * @param 
	 * @param 
	 * @return ValueObject
	 */
	public RowSet getWarrGofficeList(){

        Search search = new SearchImpl();
        RowSet listRowSet = null;
        String sqlstr = "";
        
        try {
            sqlstr += " SELECT '1' AS DETAILCD, '서울보증보험' AS DETAILNM FROM DUAL             	\n"
                    + " UNION ALL										      					\n"
                    + " SELECT '2' AS DETAILCD, '전문건설공제조합' AS DETAILNM FROM DUAL			\n"
                    + " UNION ALL										      					\n"
                    + " SELECT '3' AS DETAILCD, '건설공제조합' AS DETAILNM FROM DUAL				\n"
                    + " UNION ALL										      					\n"
                    + " SELECT '9' AS DETAILCD, '기타' AS DETAILNM FROM DUAL   					\n";
             
            search.setStatement(sqlstr);
            listRowSet = search.execute();
			
		}catch(Exception e){
			e.printStackTrace();
		}finally{

			if( listRowSet == null ){
            	listRowSet = new RowSetImpl();
            }
            
			return listRowSet;
		}
	}    
 
    /**
     * 발행구분을 조회한다.
	 * @param 
	 * @param 
	 * @return ValueObject
	 */
	public ValueObject getWarrGubun(){

        Search search = new SearchImpl();
        RowSet listRowSet = null;
        String sqlstr = "";
        ValueObject rowObject = null;
        
        try {
            sqlstr += " SELECT A.*												             		\n"
                    + " FROM (											      						\n"
                    + " 	SELECT '1' AS DETAILCD, '계약이행보증' AS DETAILNM FROM DUAL				\n"
                    + " 	UNION ALL										      					\n"
                    + " 	SELECT '2' AS DETAILCD, '하도급지급보증' AS DETAILNM FROM DUAL			\n"
                    + " 	UNION ALL										      					\n"
                    + " 	SELECT '3' AS DETAILCD, '선급금보증' AS DETAILNM FROM DUAL				\n"
                    + " 	UNION ALL										      					\n"
                    + " 	SELECT '4' AS DETAILCD, '근재보험보증' AS DETAILNM FROM DUAL				\n"
                    + " 	UNION ALL										      					\n"
                    + " 	SELECT '5' AS DETAILCD, '하자이행보증' AS DETAILNM FROM DUAL   			\n"
                    + " 	) A															   			\n"
                    + " 	WHERE DETAILCD = '"+ params.get("warrGubun") +"'			   			\n";
             
            search.setStatement(sqlstr);
            listRowSet = search.execute();
            if(listRowSet.size() != 0){
            	rowObject = RowSetUtility.getValueObject(listRowSet.getRow(0));
            }
            
		}catch(Exception e){
			e.printStackTrace();
		}finally{

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