/**
 * @(#)file    ChgItemBiz.java
 * @(#)author  Kim Myung Ho
 * @(#)version 1.0
 * @(#)date    2014-08-11
 * @(#)since   JDK 1.4.2
 */
package kr.co.udapsoft.ebid.buyer.bid.outside.biz;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.ArrayList;

import oracle.toplink.internal.ox.StrBuffer;
import kr.co.hsnc.common.base.WAFLogger;
import kr.co.hsnc.common.config.WAFConfig;
import kr.co.hsnc.common.sql.Row;
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.sql.util.RowSetUtility;
import kr.co.hsnc.common.util.ValueObject;
import kr.co.udapsoft.common.code.CommCodeManager;
import kr.co.udapsoft.common.util.Crosscert;
import kr.co.udapsoft.common.util.PDFMaker;
import kr.co.udapsoft.ebid.buyer.common.file.FileManager;
import kr.co.udapsoft.ebid.buyer.sycs.user.biz.UserCommon;

import com.udapsoft.modular.web.ibsheet7.IBSheet7Factory;
import com.udapsoft.modular.web.ibsheet7.util.IBSheet7Utils;
import com.udapsoft.waf.common.ui.InitCombo;
import com.udapsoft.waf.common.util.StringUtils;
import com.udapsoft.waf.system.Biz;
import com.udapsoft.waf.system.HandlerStorage;

   
public class BidItemBiz extends Biz {

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

	public void doBiz() throws Exception {
		params.set("sheet1", getItemList(params));		
		storage.addObject("ibsheet7Data", IBSheet7Factory.createIBSheet7(params, storage.request)); 
	} 
	
	/**
	 * 계약 변경 내역 목록
	 * @param Params
	 * @return
	 */
	private RowSet getItemList(ValueObject param) {

		Search search = new SearchImpl();
        RowSet rowSet = new RowSetImpl();
        
        StrBuffer sql = new StrBuffer();
        try{
        	sql.append(" SELECT NVL(F_GET_OUT_ITEM_NAME(SUBSTR(B.MATERIAL_CD,0,4)),'직접비') AS DEPTH1                 \n");  
            sql.append("       ,A.MATERIAL_CD                                                                         \n");
            sql.append("       ,NVL(A.ITEM_NAME, B.ITEM_NAME) ITEM_NAME                                               \n");
            sql.append("       ,SUBSTR(A.MATERIAL_CD,0,6) AS PARENT_LEVEL                                             \n");
            sql.append("       ,DECODE(B.PARENT_LEVEL,'R','',A.DEMANDED_QTY || '/'||A.STD) AS ITEMS                   \n");
            sql.append("       ,C.AMT_ORD                                                                             \n");
            sql.append("       ,C.AMT_ACT                                                                             \n");
            sql.append("   FROM BID_MASTER A0                                                                            \n");
            sql.append("       ,BID_ITEM A                                                                            \n");
            sql.append("       ,BID_OUT_ITEM_MASTER B                                                                 \n");
            sql.append("       ,PMM_DEMANDED_DETAIL C                                                                 \n");
            sql.append("  WHERE A0.BID_NO = A.BID_NO                                                                   \n");
            sql.append("    AND A0.BID_DEG = A.BID_DEG                                                                 \n");
            sql.append("    AND A.MATERIAL_CD = B.MATERIAL_CD(+)                                                      \n");
            sql.append("    AND A.CD_SITE = C.CD_SITE(+)                                                              \n");                                  
            sql.append("    AND A.CD_CSTR = C.CD_CSTR(+)                                                              \n");
            sql.append("    AND A.DL_CSTR = C.DL_CSTR(+)                                                              \n");
            sql.append("    AND A.NO_CORD = C.NO_CORD                                                                 \n");
            sql.append("    AND A.BID_NO = '"+ params.get("BID_NO") +"' 	     	                                  \n");
        	sql.append("    AND A.BID_DEG = '"+ params.get("BID_DEG") +"' 	     	                                  \n");
            sql.append("  ORDER BY A.MATERIAL_CD    	                                                              \n");
        	 
            System.out.println(sql.toString());
            search.setStatement(sql.toString());
            
            rowSet = search.execute();
        }
        catch (WAFSQLException se) {
            super.doException(se);
            this.storage.setSuccess(false);  
            this.storage.setMessage(se.getMessage());
            storage.setDetailMessage(se);
        }
        finally {    
            if(rowSet == null){
            	rowSet = new RowSetImpl();
            }
        }
        return rowSet;
	} 
	
}


