/**
 *
 * @(#)author  [ok]
 * @(#)version 1.0
 * @(#)date    2014. 06. 30
 * @(#)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.search.Search;
import kr.co.hsnc.common.sql.search.SearchImpl;
import kr.co.hsnc.common.util.ValueObject;

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

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

	public void doBiz() throws Exception {

		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. 30.
     *@since JDK1.7
     */
    public RowSet getPrePaymentList(ValueObject Params) {
        Search search = new SearchImpl();
        RowSet listRowSet = null;
        String sqlstr = "";
        
        try {
        	sqlstr += " SELECT A.SUB_CONT_ID 			  								  								\n"
        			+ "       , A.BUILD_NAME					               			  								\n"
        			+ "       , A.DEPT_NAME					               			  								\n"
        			+ "       , TO_CHAR(A.START_WORK_DATE ,'YYYY-MM-DD')||' ~ ' || TO_CHAR(A.END_WORK_DATE ,'YYYY-MM-DD') AS START_END_WORK_DATE 		            \n"
        			+ "       , A.CON_AMT          --계약금액					   			     	                        \n"
        			+ "       , A.CON_SUPPLY_AMT   --계약공급가					             	                        \n"
        			+ "       , A.CON_SUPPLY_TAMT  --계약공급가_과세				                 	                    \n"
        			+ "       , A.CON_SUPPLY_NAMT  --계약공급가_면세						                                \n"
        			+ "       , A.CON_SURTAX_AMT   --계약부가세							                                \n"
        			+ "       , NVL(C.ACMP_NO, '1') AS ACMP_NO							                                \n"
        			+ "       , NVL(C.FUND_AMT, 0) AS FUND_AMT           --금회기성			                    		\n"
        			+ "       , NVL(C.TOT_FUND_AMT, 0)  AS TOT_FUND_AMT  --누계기성		                                \n"
        			+ "       , A.CON_SUPPLY_AMT - NVL(C.TOT_FUND_AMT, 0) AS MOD_FUND_AMT    --잔여기성                     \n"
        			+ "       , ROUND((NVL(C.TOT_FUND_AMT, 0) /A.CON_SUPPLY_AMT)*100,1) FUND_RATE  --기성율                \n"
        			+ "       , C.STATUS_CD     --상태							            	                        \n"
        			+ "       , F_GET_CODE_NAME('ACMP_STATUS_CD', C.STATUS_CD) AS STATUS_NM     --상태명					\n"
        			+ "       , TO_CHAR(TO_DATE(C.ACMP_YYYYMM,'YYYYMM'),'YYYY-MM')  AS ACMP_YYYYMM --기성년월              \n"
        			+ "       , C.ACMP_ID    	 --기성ID 								                            	\n"
        			+ "       , C.ACMP_NO    	 --기성차수 								                            	\n"
        			+ "       , C.STATUS_CD       --상태	 								                            	\n"
        			+ "       , C.CON_CORP_ID     --계약업체ID							                            	\n"
        			+ "       , A.SUB_CONT_MOD_ID --변경계약ID							                            	\n"
        			+ "       , A.MOD_NO --변경계약MAX차수								                            	\n"
        			+ " FROM  SUB2000T A, SUB1020T B, SUB1040T C,								                        \n"
        			+ " 	  CONT_OUT_SUPP C1																	        \n"
        			+ " WHERE 1=1																                        \n"
        			+ " AND A.SUB_CONT_ID = C.SUB_CONT_ID										                        \n"
        			+ " AND A.MOD_NO = C.MOD_NO													                        \n"
        			+ " AND C.CON_CORP_ID = B.CON_CORP_ID										                        \n"
        			+ " AND C1.SUB_CONT_MOD_ID = A.SUB_CONT_MOD_ID								                        \n"
        			+ " AND B.MAIN_CORP = 'Y'													                        \n";
        	
        	if(!"".equals(params.get("buildName"))){
        		sqlstr += " AND UPPER(A.BUILD_NAME) LIKE UPPER('%" + params.get("buildName") + "%')						\n";
        	}
        	if(!"".equals(params.get("deptName"))){
        		sqlstr += " AND UPPER(A.DEPT_NAME) LIKE UPPER('%" + params.get("deptName") + "%')						\n";
        	}
        	if(!"".equals(params.get("searchDate"))){
        		sqlstr += " AND C.ACMP_YYYYMM = '"+Params.get("searchDate").replaceAll("-", "")+"'						\n";
        	}
        	if(!"".equals(params.get("detailcd"))){
        		sqlstr += " AND C.STATUS_CD = '"+Params.get("detailcd")+"'												\n";
        	}
        	if(!"".equals(params.get("userCorpId"))){
        		sqlstr += " AND C1.CORP_ID  = '"+Params.get("userCorpId")+"'											\n";
        	}            
            
            sqlstr += " ORDER BY A.SUB_CONT_ID  																		\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;
        }
    }
}
