/**
 *
 * @(#)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.buyer.payment.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.util.ValueObject;

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

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

	public void doBiz() throws Exception {

		if(storage.compareEvent("GET_DATA")){
			params.set("sheet1", getPaymentList(params));
			storage.addObject("ibsheet7Data", IBSheet7Factory.createIBSheet7(params, storage.request));
		}else{
			RowSet rowSet = getStatus_searchCombo(); 
			storage.addRowSet("statusComboList", rowSet);
			storage.setSuccess(true);
		}
	}

    /**
     *@param ValueObject
     *@return RowSet
     *기   능 : 기성신청현황 데이터 조회
     *@author OK
     *@version 2014. 6. 30.
     *@since JDK1.7
     */
    public RowSet getPaymentList(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(B.ACMP_NO, '1') AS ACMP_NO							                                \n"
        			+ "       , NVL(B.FUND_AMT, 0) AS FUND_AMT           --금회기성			                    		\n"
        			+ "       , NVL(B.TOT_FUND_AMT, 0)  AS TOT_FUND_AMT  --누계기성		                                \n"
        			+ "       , A.CON_SUPPLY_AMT - NVL(B.TOT_FUND_AMT, 0) AS MOD_FUND_AMT    --잔여기성                                     \n"                      
        			//+ "       , ROUND((NVL(B.TOT_FUND_AMT, 0) /A.CON_SUPPLY_AMT)*100,1) FUND_RATE  --기성율                             \n"                      
        			+ "       ,DECODE( A.CON_SUPPLY_AMT, 0, 0,ROUND((NVL(B.TOT_FUND_AMT, 0) /A.CON_SUPPLY_AMT)*100,1)) FUND_RATE  --기성율                             \n"     
        			+ "       , B.STATUS_CD     --상태							            	                        \n"
        			+ "       , F_GET_CODE_NAME('ACMP_STATUS_CD', B.STATUS_CD) AS STATUS_NM     --상태명					\n"
        			+ "       , TO_CHAR(TO_DATE(B.ACMP_YYYYMM,'YYYYMM'),'YYYY-MM')  AS ACMP_YYYYMM --기성년월                         \n"
        			+ "       , B.ACMP_ID    	 --기성ID 								                            	\n"
        			+ "       , B.ACMP_NO    	 --기성차수 								                            	\n"
        			+ "       , B.STATUS_CD       --상태	 								                            	\n"
        			+ "       , B.CON_CORP_ID     --계약업체ID							                            	\n"
        			+ "       , A.SUB_CONT_MOD_ID --변경계약ID							                            	\n"
        			+ "       , A.MOD_NO --변경계약MAX차수								                            	    \n"
        			+ "       , A.CON_DOC_NO 	           							                            	    \n"
        			+ "       , C.MEMBER_NAME CUST_NAME  	        				                            	    \n"
        			+ " FROM  SUB2000T A                								                                \n"
        			+ "      ,SUB1040T B				           				                                        \n"
        			+ " 	 ,CONT_OUT_SUPP C																	        \n"
        			+ " WHERE 1=1																                        \n"
        			+ " AND A.SUB_CONT_ID = B.SUB_CONT_ID										                        \n"
        			+ " AND A.MOD_NO = B.MOD_NO													                        \n"
        			+ " AND A.SUB_CONT_MOD_ID = C.SUB_CONT_MOD_ID								                        \n"
        			+ " AND C.SIGN_SEQ = 2										                                        \n"
        			+ " AND A.DEPT_CD = '" + params.get("dept_cd") + "'			   			                            \n";
        	if(!"".equals(params.get("searchBuildName"))){
        		sqlstr += " AND UPPER(A.BUILD_NAME) LIKE UPPER('%" + params.get("searchBuildName") + "%')						\n";
        	}
        	
        	if(!"".equals(params.get("searchDate"))){
        		sqlstr += " AND B.ACMP_YYYYMM = '"+Params.get("searchDate").replaceAll("-", "")+"'						\n";
        	}
        	if(!"".equals(params.get("detailcd"))){
        		sqlstr += " AND B.STATUS_CD = '"+Params.get("detailcd")+"'												\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;
        }
    }
    public RowSet getStatus_searchCombo(){

        Search search = new SearchImpl();
        RowSet listRowSet = null;
        String sqlstr = "";
        
        try {
            sqlstr += " SELECT DETAILCD, DETAILNM           			 		\n"
                    + " FROM EBID_COM911T										\n"
                    + " WHERE BASECD = 'ACMP_STATUS_CD'							\n";
             
            search.setStatement(sqlstr);
            listRowSet = search.execute();
			
		}catch(Exception e){
			e.printStackTrace();
		}finally{

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