/**
 *
 * @(#)author  [ok]
 * @(#)version 1.0
 * @(#)date    2014. 06. 23
 * @(#)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.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.util.ValueObject;




import kr.co.udapsoft.ebid.buyer.sycs.user.biz.UserCommon;

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

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

	public void doBiz() throws Exception {

		//System.out.println("협력업체포탈 선급금 신청_외주 데이터 조회");
		
		if(storage.compareEvent("GET_DATA")){	//데이터 조회
			params.set("sheet1", getPrePaymentList(params));
			storage.addObject("ibsheet7Data", IBSheet7Factory.createIBSheet7(params, storage.request));
		}
	}

    /**
     *@param ValueObject
     *@return RowSet
     *기   능 : 선급금 신청 데이터 조회
     *@author OK
     *@version 2014. 6. 23.
     *@since JDK1.7
     */
    public RowSet getPrePaymentList(ValueObject Params) {
        Search search = new SearchImpl();
        RowSet listRowSet = null;
        String sqlstr = "";
        
        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"
        			+ "     A1.DEPT_CD,	                			  																				\n"
        			+ "     A1.BUILD_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"
        			+ "     B1.PREPAY_SUPPLY_AMT as PREPAY_AMT,   	--선급금공급가           			  																			\n"
        			+ "     NVL(B1.REQ_PREPAY_SUPPLY_AMT, 0) AS REQ_PREPAY_AMT,    --신청_선급금_공급가																\n"
        			+ "     TO_CHAR(B1.SIGN_DT, 'YYYY-MM-DD') AS SIGN_DT,	--신청일																	\n"
        			+ "     NVL(B1.STATUS_CD, '00') AS STATUS_CD,   --신청구분																		\n"
        			+ "     NVL(B1.REQ_DIV_CD, '1') AS REQ_DIV_CD   --상태 																			\n"
        			+ " FROM 				                			  																			\n"
        			+ "      SUB2000T A1,	                			  																			\n"
        			+ "      SUB1030T B1	                			  																			\n"
        			+ "      ,CONT_OUT_SUPP C1                			  																			\n"
        			+ " WHERE A1.SUB_CONT_MOD_ID = B1.SUB_CONT_MOD_ID																				        \n"
        			+ " AND A1.CON_CLS_YN = '9'																								        \n"
        			+ " AND A1.PREPAY_AMT > 0																								        \n"
        			+ " AND B1.STATUS_CD NOT IN('10', '11')																					        \n"
        			+ " AND A1.SUB_CONT_MOD_ID = C1.SUB_CONT_MOD_ID																			        \n"
        			+ " AND C1.SIGN_SEQ = 2																									        \n"
        			;
        	
        	if(!"".equals(params.get("searchBuildName"))){
        		sqlstr += " AND UPPER(A1.BUILD_NAME) LIKE UPPER('%" + params.get("searchBuildName") + "%')											\n";
        	}
        	if(!"".equals(params.get("searchStatusCd"))){
        		sqlstr += " AND B1.STATUS_CD = '"+Params.get("searchStatusCd")+"'																	\n";
        	}
        	if(!"".equals(params.get("signDt_from"))){
        		sqlstr += " AND TO_CHAR(B1.SIGN_DT, 'YYYY-MM-DD') >= '"+Params.get("signDt_from")+"'												\n";
        	}
        	if(!"".equals(params.get("signDt_to"))){
        		sqlstr += " AND TO_CHAR(B1.SIGN_DT, 'YYYY-MM-DD') <= '"+Params.get("signDt_to")+"'													\n";
        	}            
        	if(!"".equals(params.get("userCorpId"))){
        		sqlstr += " AND C1.CORP_ID  = '"+Params.get("userCorpId")+"'																		\n";
        	}            
            sqlstr += " ORDER BY SUB_CONT_MOD_ID DESC																								\n" ; 
            search.setStatement(sqlstr);
            //System.out.println(sqlstr);
            listRowSet = search.execute();
           
        }
        catch(Exception e) {
            WAFLogger.error(this.getClass().getName() + " --> getPrePaymentList() : " + e.getMessage());
            WAFLogger.error("SQL : " + search.getStatement());
            WAFLogger.error(e);
            return null;
        }
        finally {

            if( listRowSet == null ) listRowSet = new RowSetImpl();
            return listRowSet;
        }
    }
}
