package com.steering.pss.ydm.Report;

import java.util.ArrayList;

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

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

public class FrmrptProductStorage extends DBCommon {
	/***
	 * 获取期初时间
	 * @param list
	 * @return
	 */
    public CoreReturnObject getOriginaldate(ArrayList<String> list,String supplyUnit)
    {
		String sql = CoreXmlSqlParsersFactory.getSql("FrmrptProductStorage.getOriginaldate");
		if(supplyUnit.equals("120501"))
		{
			sql += " AND (T.SUPPLY_UNIT_CODE = '"+supplyUnit+"' OR T.SUPPLY_UNIT_CODE IS NULL)";
		}else if(supplyUnit.equals("120504")){
			sql += " AND T.SUPPLY_UNIT_CODE = '"+supplyUnit+"'";
		}
    	return this.getDataBySqlID(sql, list.toArray());
    }
    
    /**
     * 获取期初重量
     * @param strWhere
     * @return
     */
    public CoreReturnObject getOriginalLast(String time,String strWhere,String[] arr,String supplyUnit)
    {
		String strSuppplyUnit="";
		String sql  = "";
		if(supplyUnit.equals("120501"))
		{
			strSuppplyUnit += " AND (T.SUPPLY_UNIT_CODE = '"+supplyUnit+"' OR T.SUPPLY_UNIT_CODE IS NULL)";
		}else if(supplyUnit.equals("120504")){
			strSuppplyUnit += " AND T.SUPPLY_UNIT_CODE = '"+supplyUnit+"'";
		}

			sql = CoreXmlSqlParsersFactory.getSql("FrmrptProductStorage.getOriginalLast").replace("#condtions#", strWhere+strSuppplyUnit);
			sql += CoreConverter.toSqlConditionString("t.BELONG_CODE", arr);
			sql += " group by t.PRODUCNAME,t.STEELNAME,t.SPEC_NAME,t.MODEL_DESC,t.STD_STYLE_DESC,t.BELONG_NAME,t.GRADENAME,t.PROCESS_CDOE,t.IS_DEALER";

    	return this.getData(sql,new Object[]{time});
    }
    
    
    /***
     * 上期入库量
     * @param list
     * @return
     */
    public CoreReturnObject getLastIn(String strOriginalLast,String strDateFrom,String strWhere,String[] arr,String supplyUnit)
    {
		String strSuppplyUnit="";
		String sql = "";
		if(supplyUnit.equals("120501"))
		{
			strSuppplyUnit += " AND (T.SUPPLY_UNIT_CODE = '"+supplyUnit+"' OR T.SUPPLY_UNIT_CODE IS NULL)";
		}else if(supplyUnit.equals("120504")){
			strSuppplyUnit += " AND T.SUPPLY_UNIT_CODE = '"+supplyUnit+"'";
		}


			sql = CoreXmlSqlParsersFactory.getSql("FrmrptProductStorage.getLastIn").replace("#condtions#", strWhere+ strSuppplyUnit);
			sql += CoreConverter.toSqlConditionString("t.BELONG_CODE", arr);
			sql += " group by t.PRODUCNAME, t.STEELNAME,t.MODEL_DESC,t.SPEC_NAME,t.STD_STYLE_DESC,t.BELONG_NAME,t.GRADENAME,T.PROCESS_CDOE,t.IS_DEALER";

    	return this.getData(sql, new Object[]{strDateFrom,strOriginalLast});
    }
    
    /***
     * 上期出库量
     * @param strOriginalLast
     * @param strDateFrom
     * @param strWhere
     * @return
     */
    public CoreReturnObject getLastOut(String strOriginalLast,String strDateFrom,String strWhere,String[] arr,String supplyUnit)
    {
		String strSuppplyUnit="";
		String sql = "";
		if(supplyUnit.equals("120501"))
		{
			strSuppplyUnit += " AND (T.SUPPLY_UNIT_CODE = '"+supplyUnit+"' OR T.SUPPLY_UNIT_CODE IS NULL)";
		}else if(supplyUnit.equals("120504")){
			strSuppplyUnit += " AND T.SUPPLY_UNIT_CODE = '"+supplyUnit+"'";
		}

			sql = CoreXmlSqlParsersFactory.getSql("FrmrptProductStorage.getLastOut").replace("#condtions#", strWhere + strSuppplyUnit);
			sql += CoreConverter.toSqlConditionString("t.BELONG_CODE", arr);
			sql += " group by t.PRODUCNAME, t.STEELNAME,t.SPEC_NAME,t.MODEL_DESC,t.STD_STYLE_DESC,t.BELONG_NAME,t.GRADENAME,t.PROCESS_CDOE,t.IS_DEALER";

    	return this.getData(sql, new Object[]{strDateFrom,strOriginalLast});
    }
    
    /***
     * 本期入库量
     * @param strOriginal
     * @param strDateFrom
     * @param strDateTo
     * @param strWhere
     * @return
     */
    public CoreReturnObject getThisIn(String strOriginal,String strDateFrom,String strDateTo,String strWhere,String[] arr,String supplyUnit,String ssq)
    {
		String strSuppplyUnit="";
		String sql  = "";
		if(supplyUnit.equals("120501"))
		{
			strSuppplyUnit += " AND (T.SUPPLY_UNIT_CODE = '"+supplyUnit+"' OR T.SUPPLY_UNIT_CODE IS NULL)";
		}else if(supplyUnit.equals("120504")){
			strSuppplyUnit += " AND T.SUPPLY_UNIT_CODE = '"+supplyUnit+"'";
		}
		String ssqrkString = "";
		if(ssq.equals("1")){
        	ssqrkString = " AND INSTOCK_TYPE_CODE IN ('800701', '800702', '800704', '800706', '800707', '800712') ";
        }else{
        	ssqrkString = " AND INSTOCK_TYPE_CODE IN ('800701', '800702', '800704', '800706', '800707') ";
        }

			sql = CoreXmlSqlParsersFactory.getSql("FrmrptProductStorage.getThisIn").replace("#condtions#", strWhere+ strSuppplyUnit+ssqrkString);
			sql += CoreConverter.toSqlConditionString("t.BELONG_CODE", arr);
			sql += " group by t.PRODUCNAME, t.STEELNAME,t.SPEC_NAME,t.MODEL_DESC,t.STD_STYLE_DESC,t.BELONG_NAME,t.GRADENAME,t.PROCESS_CDOE,t.IS_DEALER";

    	return this.getData(sql, new Object[]{strDateTo,strDateTo,strDateFrom,strDateTo,strDateFrom,strDateTo,strOriginal,strDateTo});
    }
    
    /***
     * 本期出库量
     * @param strOriginal
     * @param strDateFrom
     * @param strDateTo
     * @param strWhere
     * @return
     */
    public CoreReturnObject getThisOut(String strOriginal,String strDateFrom,String strDateTo,String strWhere,String[] arr,String supplyUnit,String ssq)
    {
		String strSuppplyUnit="";
		String sql = "";
		if(supplyUnit.equals("120501"))
		{
			strSuppplyUnit += " AND (T.SUPPLY_UNIT_CODE = '"+supplyUnit+"' OR T.SUPPLY_UNIT_CODE IS NULL)";
		}else if(supplyUnit.equals("120504")){
			strSuppplyUnit += " AND T.SUPPLY_UNIT_CODE = '"+supplyUnit+"'";
		}
		String ssqckString = "";
		if(ssq.equals("1")){
			ssqckString = " AND OUTSTOCK_TYPE_CODE IN ('800805', '800804', '800802', '800808', '800806', '800812') ";
        }else{
        	ssqckString = " AND OUTSTOCK_TYPE_CODE IN ('800805', '800804', '800802', '800808', '800806') ";
        }

			sql = CoreXmlSqlParsersFactory.getSql("FrmrptProductStorage.getThisOut").replace("#condtions#", strWhere+ strSuppplyUnit+ ssqckString);
			sql = sql.replace("#condtions1#", strWhere);
			sql += CoreConverter.toSqlConditionString("t.BELONG_CODE", arr);
			sql += " group by t.PRODUCNAME,t.STEELNAME,t.SPEC_NAME,t.MODEL_DESC,t.STD_STYLE_DESC,t.BELONG_NAME,t.GRADENAME,t.PROCESS_CDOE,t.IS_DEALER";



    	return this.getData(sql, new Object[]{strDateTo,strDateTo,strDateFrom,strDateTo,strDateFrom,strDateTo,strOriginal,strDateTo});
    	                                      
    			//,strDateTo,strDateTo,strDateTo,strOriginal,strDateTo});
    }
    
    /***
     * 调差量
     * @param strDateFrom
     * @param strDateTo
     * @param strWhere
     * @param arr
     * @return
     */
    public CoreReturnObject getAdjust(String strDateFrom,String strDateTo,String strWhere,String[] arr,String supplyUnit)
    {
		String strSuppplyUnit="";
		String sql  = "";
		if(supplyUnit.equals("120501"))
		{
			strSuppplyUnit += " AND (T.SUPPLY_UNIT_CODE = '"+supplyUnit+"' OR T.SUPPLY_UNIT_CODE IS NULL)";
		}else if(supplyUnit.equals("120504")){
			strSuppplyUnit += " AND T.SUPPLY_UNIT_CODE = '"+supplyUnit+"'";
		}

			sql = CoreXmlSqlParsersFactory.getSql("FrmrptProductStorage.getAdjust").replace("#condtions#", strWhere+strSuppplyUnit);
			sql += CoreConverter.toSqlConditionString("t.BELONG_CODE", arr);
			sql += " group by t.PRODUCNAME,t.STEELNAME,t.MODEL_DESC,t.SPEC_NAME,t.STD_STYLE_DESC,t.BELONG_NAME,t.GRADENAME,T.PROCESS_CDOE,t.IS_DEALER";

    	return this.getData(sql,new Object[]{strDateFrom,strDateTo});
    }

    /***
     * 实时库存量
     * @param strDateFrom
     * @param strDateTo
     * @param strWhere
     * @param arr
     * @return
     */
    public CoreReturnObject getMatData(String strDateFrom,String strDateTo,String strWhere,String[] arr,String supplyUnit)
    {
    	String strSuppplyUnit="";
    	String sql = "";
		if(supplyUnit.equals("120501"))
		{
			strSuppplyUnit += " AND (T.SUPPLY_UNIT_CODE = '"+supplyUnit+"' OR T.SUPPLY_UNIT_CODE IS NULL)";
		}else if(supplyUnit.equals("120504")){
			strSuppplyUnit += " AND T.SUPPLY_UNIT_CODE = '"+supplyUnit+"'";
		}

			sql = CoreXmlSqlParsersFactory.getSql("FrmrptProductStorage.getMatData").replace("#condtions#", strWhere+strSuppplyUnit);
			sql += CoreConverter.toSqlConditionString("t.BELONG_CODE", arr);
			sql += " group by t.PRODUCNAME,t.STEELNAME,t.MODEL_DESC,t.SPEC_NAME,t.STD_STYLE_DESC,t.BELONG_NAME,t.GRADENAME,T.PROCESS_CDOE,t.IS_DEALER";

    	return this.getData(sql);
    }
}
