/**
 * @(#)file    BidPlanBiz.java
 * @(#)author  Son Hyung Min 
 * @(#)version 1.0
 * @(#)date    2014-06-23
 * @(#)since   JDK 1.4.2
 */
package kr.co.udapsoft.ebid.buyer.quot.outside.biz;



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.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 oracle.toplink.internal.ox.StrBuffer;

import com.udapsoft.waf.system.Biz;
import com.udapsoft.waf.system.HandlerStorage;

   
public class QuotAmtPopBiz extends Biz {

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

	public void doBiz() throws Exception {
		if(storage.compareEvent("")){	//견적 현황 리스트 조회
			ValueObject vo = getQuotSuppValueObject(params);
	        storage.addValueObject("Order", vo);
			ValueObject att_file = new ValueObject();

	        /**		파일 목록 조회			 **/
	        RowSet rowSet = FileManager.getFileList("QUOT_SUPP_" + params.get("VENDOR_CD") + params.get("quot_id"), "");
	        String str="";
		    
		    for(int i=0;i<rowSet.size();i++){
			   	Row row=rowSet.getRow(i);
			   	str += (i+1)+" : "+row.get("FILE_NAME")+" ("+ row.get("FILE_SIZE")+")";
			   	if(i+1!=rowSet.size()){
			   		str +="\r\n";
			   	}
		    }
	        att_file.set("ATT_ID", str);
	        storage.addValueObject("ATT_ID", att_file);
		}
	}

	
	/**
	 * 견적 현황 상세를 검색하여 리턴
	 * @param Params
	 * @return
	 */
	private ValueObject getQuotSuppValueObject(ValueObject params) {

		Search search = new SearchImpl();
        RowSet rowSet = new RowSetImpl();
        ValueObject valueobject = null;
     //   String sqlstr = "";
        StrBuffer sqlstr = new StrBuffer();
        try{
        	sqlstr.append("SELECT A.QUOT_BID_NO,                                                    \n");
        	sqlstr.append("       A.QUOT_BID_DEG,                                                   \n");
        	sqlstr.append("       A.QUOT_BID_MASTER_NM,                                             \n");
        	sqlstr.append("       A.QUOT_ID,                                                        \n");
        	sqlstr.append("       TO_CHAR (A.REQUEST_DATE, 'YYYY-MM-DD') AS REQUEST_DATE,           \n");
        	sqlstr.append("       A.QUOT_TYPE,                                                      \n");
        	sqlstr.append("       A.DEPT_CD,                                                        \n");
        	sqlstr.append("       A.DEPT_NM,                                                        \n");
        	sqlstr.append("       A.REQUEST_MAN_ID,                                                 \n");
        	sqlstr.append("       A.REQUEST_MAN_NM,                                                 \n");
        	sqlstr.append("       A.REQUEST_DEPT_NM,                                                \n");
        	sqlstr.append("       A.REQUEST_DEPT_CD,                                                \n");
        	sqlstr.append("       TO_CHAR (A.START_WORK_DATE, 'YYYY-MM-DD') AS START_WORK_DATE,     \n");
        	sqlstr.append("       TO_CHAR (A.END_WORK_DATE, 'YYYY-MM-DD') AS END_WORK_DATE,         \n");
        	sqlstr.append("       A.WORK_SIZE,                                                      \n");
        	sqlstr.append("       A.DEALER_NM,                                                      \n");
        	sqlstr.append("       A.SUPERVISOR,                                                     \n");
        	sqlstr.append("       A.QUOT_MAN_ID,                                                    \n");
        	sqlstr.append("       A.QUOT_MAN_NM,                                                    \n");
        	sqlstr.append("       A.QUOT_MAN_TELNO,                                                 \n");
        	sqlstr.append("       A.QUOT_MAN_EMAIL,                                                 \n");
        	sqlstr.append("       A.QUOT_MAN_FAX,                                                   \n");
        	sqlstr.append("       A.QUOT_DEPT_CD,                                                   \n");
        	sqlstr.append("       A.QUOT_VALIDATE,                                                  \n");
        	sqlstr.append("       A.WORK_PLACE,                                                     \n");
        	sqlstr.append("       A.ITEM_NM,                                                        \n");
        	sqlstr.append("       TO_CHAR (A.QUOT_BID_FROM_DT, 'YYYY-MM-DD') AS QUOT_BID_FROM_DT,   \n");
        	sqlstr.append("       TO_CHAR (A.QUOT_BID_TO_DT, 'YYYY-MM-DD') AS QUOT_BID_TO_DT,       \n");
        	sqlstr.append("       A.INNER_REMARKS,                                                  \n");
        	sqlstr.append("       A.OUTER_REMARKS,                                                  \n");
        	sqlstr.append("       A.DOC_ETC_IN,                                                     \n");
        	sqlstr.append("       A.DOC_ETC_OUT,                                                    \n");
        	sqlstr.append("       A.STATUS_CD,                                                      \n");
        	sqlstr.append("       F_GET_CODE_NAME ('QUOT_STATUS_CD', STATUS_CD) AS STATUS_NM,       \n");
        	sqlstr.append("       B.VENDOR_CD,                                                      \n");
        	sqlstr.append("       B.VENDOR_NO,                                                      \n");
        	sqlstr.append("       VENDOR_NAME,                                                      \n");
        	sqlstr.append("       B.REPRE_NO,                                                       \n");
        	sqlstr.append("       B.CHARGE_NAME,                                                    \n");
        	sqlstr.append("       B.CHAGE_HP,                                                       \n");
        	sqlstr.append("       B.CHARGE_EMAIL,                                                   \n");
        	sqlstr.append("       NVL(B.BID_STATUS_CD,'00') AS BID_STATUS_CD,                       \n");
        	sqlstr.append("       F_GET_CODE_NAME ('QUOT_SUPP_STATUS_CD', NVL(B.BID_STATUS_CD,'00')) AS SUPP_STATUS_NM,			\n");
        	sqlstr.append("       B.ATT_ID,                                                         \n");
        	sqlstr.append("       B.FILE_GB,                                                        \n");
        	sqlstr.append("       TO_CHAR (B.ESTI_TOT_AMT, '999,999,999,999,999') AS ESTI_TOT_AMT,  \n");
        	sqlstr.append("       B.REMARK,                                                         \n");
        	sqlstr.append("       DECODE(B.SUBMIT_DT, '', '미제출', TO_CHAR (B.SUBMIT_DT, 'YYYY-MM-DD HH24:MI:SS')) SUBMIT_DT,	\n");
        	sqlstr.append("       DECODE(A.STATUS_CD,'10','불가','가능') AS SUBMIT_YN,                \n");
        	sqlstr.append("       B.SITE_ATTEND_YN,                                                 \n");
        	sqlstr.append("       B.SITEPARTI_YN,                                                   \n");
        	sqlstr.append("       B.SITE_ATTEND_REASON,                                             \n");
        	sqlstr.append("       B.ON_SUPP_YN,                                                     \n");
        	sqlstr.append("       B.IN_OUT_DIV                                                      \n");
        	sqlstr.append("  FROM QUOT_BID_MASTER A                                                 \n");
        	sqlstr.append("     , QUOT_BID_SUPP B                                                   \n");
        	sqlstr.append(" WHERE 1=1                                                               \n");
        	sqlstr.append("   AND A.QUOT_ID = '"+params.get("QUOT_ID")+"'                           \n");
        	sqlstr.append("   AND A.QUOT_BID_NO = B.QUOT_BID_NO                                     \n");
        	sqlstr.append("   AND A.QUOT_BID_DEG = B.QUOT_BID_DEG                                   \n");
        	sqlstr.append("   AND B.VENDOR_CD = '"+params.get("VENDOR_CD")+"'                       \n");
        	search.setStatement(sqlstr.toString());
        	
            rowSet = search.execute();
            
            if( rowSet != null && rowSet.size() > 0 ){
            	valueobject = RowSetUtility.getValueObject(rowSet.getRow(0));
            }
            	
        }
        catch(WAFSQLException se) {
        	super.doException(se);
            this.storage.setSuccess(false);
            this.storage.setMessage(se.getMessage());
            storage.setDetailMessage(se);
        }
        finally {

        	if( valueobject == null ) valueobject = new ValueObject();
            return valueobject;
        }
	}
}