/**
 * @(#)file    PreRequestSignBiz.java
 * @(#)author  OK
 * @(#)version 1.0
 *
 * Copyright (c) www.udapsoft.co.kr, Inc.
 */
package kr.co.udapsoft.ebid.buyer.cont.purchase.biz;

import oracle.toplink.internal.ox.StrBuffer;
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.WAFSQLException;
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.waf.system.Biz;
import com.udapsoft.waf.system.HandlerStorage;

/**
 * 
 * @version 1.0
 */
public class ContInsurSignBiz extends Biz {
	FileManager FileManager = new FileManager();
	public ContInsurSignBiz(HandlerStorage storage) {
		super(storage);
	}

	public void doBiz() throws Exception {
		
		ValueObject vo = new ValueObject();

		vo = getContInfo(params.get("sign_key1"), params.get("acct_id"));
 
        String doctitle = "["+vo.get("DEPT_NM") + "]" + vo.get("CST_DOC_NAME");
        vo.set("doctitle", doctitle);   	
    	
		storage.addValueObject("ContInfo", vo);
   }
	
	public ValueObject getContInfo(String sign_cont_mod_id, String acct_id) {
		Search search = new SearchImpl();
		RowSet listRowSet = null;
		StrBuffer sqlstr = new StrBuffer();
		ValueObject rowObject = null;

		try {
			
			sqlstr.append("	     SELECT 'P' SIGN_GB                                                                                                                        \n");
			sqlstr.append("	        ,A.DEALER_NM M_MEMBER_NAME -- 사업주명                                                                                     \n");                       
			sqlstr.append("	        ,C.MEMBER_NAME S_MEMBER_NAME -- 공급자                                                                                      \n");                        
			sqlstr.append("	        ,C.BOSS_NAME BOSS_NAME -- 대표자                                                                                      \n");                        
			sqlstr.append("	        ,C.TEL_NUM TEL_NUM -- 전화번호                                                                                      \n");                        
			sqlstr.append("	        ,C.ADDRESS ADDRESS -- 전화번호                                                                                      \n");                        
			sqlstr.append("	        ,A.CST_DOC_NAME  AS CST_DOC_NAME-- 계약명                                                                                     \n");                        
			sqlstr.append("	        ,F_GET_D_CURRENCY(A.ORD_SUPPLY_AMT, D.CHG_CODE01) AS  CON_SUPPLY_AMT-- 현_계약금액                                          \n");                                                        
			sqlstr.append("	        ,A.FRST_CON_AMT -- 원도급금액                                                                                               \n");                        
			sqlstr.append("	        ,A.CHG_CON_AMT -- 현_도급금액                                                                                               \n");                        
			sqlstr.append("	        ,A.FRST_EXE_AMT -- 원_실행금액                                                                                              \n");                        
			sqlstr.append("	        ,A.CHG_EXE_AMT -- 현_실행금액                                                                                               \n");                        
			sqlstr.append("	        ,TO_CHAR(A.ORD_START_DATE, 'YYYY-MM-DD') AS  START_WORK_DATE -- 현_납품시작일                                                                      \n");                        
			sqlstr.append("	        ,TO_CHAR(A.ORD_END_DATE, 'YYYY-MM-DD')  AS END_WORK_DATE -- 현_납품종료일                                                                          \n");                        
			sqlstr.append("	        ,A.IN_SPE_INFO -- 내부특기사항                                                                                              \n");                        
			sqlstr.append("	        ,A.IN_CHG_INFO -- 내부변경사유                                                                                              \n");                        
			sqlstr.append("	        ,A.ORD_DOC_NO               AS ORD_DOC_NO                                                                                   \n");                        
			sqlstr.append("	        ,A.DEPT_CD                                                                                                                  \n");                        
			sqlstr.append("	        ,GET_DEPT_NM(A.DEPT_CD)  AS DEPT_NM                                                                                                                  \n");                        
			sqlstr.append("	        ,A.CURRENCY_GB          AS CURRENCY_GB                                                                                       \n");                        
			sqlstr.append("	        ,D.CHG_CODE06                                                                                                               \n");                        
			sqlstr.append("	        ,D.CHG_CODE09                                                                                                               \n");                        
			sqlstr.append("	        ,D.CHG_CODE01     AS DIGIT                                                                                                  \n");                        
			sqlstr.append("	        ,A.PUR_CONT_MOD_ID                                                                                                          \n");                        
			sqlstr.append("	        ,A.PUR_CONT_ID                                                                                                              \n");                        
			sqlstr.append("	        ,A.MOD_NO                                                                                                                   \n");
			sqlstr.append("	        ,E.INSUR_EMPL_YN                                                                                                            \n");
			sqlstr.append("	        ,E.INSUR_ACC_YN                                                                                                             \n");
			sqlstr.append("	        ,E.WORK_MNGR_NO                                                                                                             \n");
			sqlstr.append("	        ,E.BIZ_REG_NO                                                                                                               \n");
			sqlstr.append("	        ,E.CORP_REG_NO                                                                                                              \n");
			sqlstr.append("	        ,E.LCNS_NM                                                                                                                  \n");
			sqlstr.append("	        ,E.LCNS_REG_NO                                                                                                              \n");
			sqlstr.append("	        ,TO_CHAR(E.LCNS_ACQT_DATE, 'YYYY-MM-DD') AS LCNS_ACQT_DATE                                                                  \n");
			sqlstr.append("	        ,F_GET_D_CURRENCY(E.MTIL_AMT      , D.CHG_CODE01)                            AS MTIL_AMT                                    \n");
			sqlstr.append("	        ,E.WORK_PLACE                                                                                                               \n");
			sqlstr.append("	        ,E.SUB_PLACE_NO                                                                                                             \n");
			sqlstr.append("	        FROM PUR2000T A                                                                                                             \n");                        
			sqlstr.append("	        ,CONT_PUR_SUPP B                                                                                                            \n");                        
			sqlstr.append("	        ,CONT_PUR_SUPP C                                                                                                            \n");                        
			sqlstr.append("	        ,(SELECT CHG_CODE06, CHG_CODE09 , DETAILCD , CHG_CODE01  FROM EBID_COM911T WHERE BASECD = '911' ) D                        \n");
			sqlstr.append("	        ,CONT_PUR_INSUR E                                                                                                           \n");
			sqlstr.append("	        WHERE A.PUR_CONT_MOD_ID = B.PUR_CONT_MOD_ID                                                                                 \n");                        
			sqlstr.append("	        AND A.PUR_CONT_MOD_ID = C.PUR_CONT_MOD_ID                                                                                   \n");                        
			sqlstr.append("	        AND A.CURRENCY_GB = D.DETAILCD                                                                                               \n");                        
			sqlstr.append("	        AND B.SIGN_SEQ = 1                                                                                                          \n");                        
			sqlstr.append("	        AND C.SIGN_SEQ = 2                                                                                                          \n");
			sqlstr.append("	        AND A.PUR_CONT_MOD_ID = E.PUR_CONT_MOD_ID                                                                                   \n");                                               
			sqlstr.append("	        AND A.PUR_CONT_MOD_ID =  '"+sign_cont_mod_id+"'    																			\n");
			
			
			search.setStatement(sqlstr.toString());
			listRowSet = search.execute();
			//WAFLogger.debug("size : " + listRowSet.size());
			rowObject = RowSetUtility.getValueObject(listRowSet.getRow(0));
			
		} catch (Exception e) {
			WAFLogger.error(this.getClass().getName()
					+ " --> getBidMaster() : " + e.getMessage());
			WAFLogger.error("SQL : " + search.getStatement());
			WAFLogger.error(e);
			return null;
		} finally {
			if (rowObject == null)
				rowObject = new ValueObject();
			return rowObject;
		}
	}
}
