/**
 * @(#)file    SuppRequestSignBiz.java
 * @(#)author  mklee 2017-02-20
 * @(#)version 1.0
 *
 * Copyright (c) www.udapsoft.co.kr, Inc.
 */
package kr.co.udapsoft.ebid.buyer.supplier.outside.biz;

import kr.co.hsnc.common.base.WAFLogger;
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 com.udapsoft.waf.system.Biz;
import com.udapsoft.waf.system.HandlerStorage;


/**
 * 
 * @version 1.0
 */
public class SuppRequestSignBiz extends Biz {

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

    public void doBiz() throws Exception {
    	ValueObject vo = new ValueObject();
        String corp_id = params.get("p_corp_id"); 
        String docTitle = "";
        
        vo = getCustItem(corp_id);	//계약정보조회
        storage.addValueObject("custList", vo);
        
        RowSet getFileListRowSet = getFileListRowSet("SUPP_DEPT_REQ_"+params.get("p_corp_id"), ""); //파일정보
		storage.addRowSet("getFileListRowSet", getFileListRowSet);
        
		docTitle = "["+vo.get("CORP_KOR") + "]" ;
        params.set("docTitle", docTitle);        
   }

    public ValueObject getCustItem(String tmpslip_purContId) {
        Search search = new SearchImpl();
        RowSet listRowSet = null;
        StringBuffer sqlstr = new StringBuffer();
        ValueObject rowObject = null;
        
        try {

        	sqlstr.append("      SELECT                                                                                                 \n")                    
            .append("              A.CORP_REG_NO                                                                                        \n")                     
            .append("            , A.CORP_KOR                                                                                           \n")
            .append("            , A.REP_NAME                                                                                           \n")
            .append("            , A.CRE_DATE                                                                                           \n")
            .append("            , A.STATUS STATUS_CODE                                                                                 \n")
            .append("            , A.USER_NAME                                                                                          \n")
            .append("            , A.EMAIL                                                                                              \n")
            .append("            , A.HP1                                                                                                \n")
            .append("            , A.HP2                                                                                                \n")
            .append("            , A.HP3                                                                                                \n")
            .append("            , A.CORP_ID                                                                                            \n")
            .append("            , A.JOB_DIV                                                                                            \n")
            .append("            , A.REQ_DATE, A.REQ_REMARK, A.REQ_EMP, A.DEPT_NM,  A.CRE_BY, A.REJECT_REASON                           \n")
            .append("            , F_GET_CODE_NAME2('CREDIT_CD', A.CREDIT_CD ) CREDIT_CD                                                \n")
            .append("            , F_GET_CODE_NAME2('CREDIT_VALUE', A.CREDIT_VALUE) CREDIT_VALUE                                        \n")
            .append("            , A.SYEAR                                                                                              \n")
            .append("            , A.DEBT_AMT                                                                                           \n")
            .append("            , A.CAPITAL_AMT                                                                                        \n")
            .append("            , A.DEBT_RATE                                                                                          \n")
            .append("            , A.LIQUID_ASSET                                                                                       \n")
            .append("            , A.LIQUID_DEBT                                                                                        \n")
            .append("            , A.LIQUID_RATE                                                                                        \n")
            .append("            , DECODE(NVL(A.LICENCE_YN,'N'), 'N', '미보유', 'Y', '보유', 'T', '장비임대/설계/인허가') LICENCE_YN         \n")
            .append("            , DECODE(NVL(A.ETC_YN,'N'), 'N', '장비임대/설계/인허가 미보유', '장비임대/설계/인허가 보유')  ETC_YN             \n")
            .append("            , C.USER_NAME CRE_EMP_NM                                                                               \n")
            .append("            , C.DEPART_DEPT_NM WRITE_DEPT                                                                          \n")
            .append("            , F_GET_CODE_NAME2('CASH_GRADE', A.CASH_GRADE) CASH_GRADE                                              \n")
            .append("        FROM SUPP_INFO_REQ A,   PUB0120T C                                                                         \n")
            .append("       WHERE A.CRE_BY = C.ACCT_ID(+)                                                                               \n")
            .append("         AND A.CORP_ID = ?                                                                                         \n");
        	
        	
        	 search.setStatement(sqlstr.toString());
             search.addParameter(params.get("p_corp_id"));
             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 RowSet getFileListRowSet(String id, 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(" 		   A.DETAILSORTNM,							\n");
    		sql.append(" 		   B.ID AS DOC_CD							\n");
    		sql.append("	FROM EBID_COM911T A, PUB0510T B					\n");
    		sql.append("	WHERE A.BASECD = 'OUT_SUPP_REQ_FILE'		    \n");
    		sql.append("	AND A.DETAILCD = B.ID(+)						\n");
    		sql.append("	AND B.FILE_GB(+) = '"+id+"'						\n");
    		sql.append("	ORDER BY A.DETAILCD								\n");
    		
            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;
    }
    
}
