package com.steering.pss.ydm.Report;

import java.util.ArrayList;
import java.util.List;

import CoreFS.SA06.CoreReturnObject;
import CoreFS.SA08.CoreXmlSqlParsersFactory;

import com.steering.comm.converter.CoreConverter;
import com.steering.comm.db.DBCommon;

public class FrmOutFactory extends DBCommon {

	public CoreReturnObject getOutFactory(String billNo, String beginTime,
			 String[] dataPurviews,String supplyUnit) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmOutFactory.getOutFactory");
		//List<String> params = new ArrayList<String>();
		
		//params.add(billNo);
		if(!billNo.equals(""))
		{
			sql += " AND UPPER(T1.BILL_NO) = UPPER(?)";
		}
		if (!beginTime.equals("")) {
			///params.add(beginTime);
			//params.add(endTime);
			//sql += " AND T1.CREATE_TIME BETWEEN TO_DATE('"+beginTime+"', 'YYYY-MM-DD HH24:MI:SS')  AND TO_DATE('"+endTime+"', 'YYYY-MM-DD HH24:MI:SS')";
			sql += " AND T1.BAL_YEAR_MONTH = '"+beginTime+"'";
		}
		if(supplyUnit.equals("120501"))
		{
			sql += " AND (T2.SUPPLY_UNIT = '"+supplyUnit+"' OR T2.SUPPLY_UNIT IS NULL)";
		}else if(supplyUnit.equals("120504")){
			sql += " AND T2.SUPPLY_UNIT = '"+supplyUnit+"'";
		}
		sql += CoreConverter.toSqlConditionString("T2.MANAGEMENT_NO",
				dataPurviews);//T1.ACT_LEN_MIN,T1.ACT_LEN_MAX,
		sql += "GROUP BY T1.BILL_NO,   T1.ORDER_NO, T1.ORDER_SEQ,T1.RECEIV_NM,T1.SPCL_LN_NM,T1.TRANS_TPE,T1.STATION_NM,"
				+ "T1.PRODUCNAME,T1.GRADENAME,T1.SPEC_NAME,T1.MODEL_DESC,T1.STD_NAME,"
				+ "T1.MEMO,T2.MANAGEMENT_NAME,T2.PLAN_NUM,T2.PLAN_WT,T4.STORAGE_NAME,T2.DELVRY_ADDR ";
		sql += " ORDER BY T1.BILL_NO,T1.ORDER_NO,T1.ORDER_SEQ";
		return this.getData(sql);
	}
}
