package com.steering.pss.ydm.Report;

import CoreFS.SA06.CoreReturnObject;
import CoreFS.SA08.CoreXmlSqlParsersFactory;
import com.steering.comm.converter.CoreConverter;
import com.steering.comm.db.DBCommon;

import java.util.ArrayList;

public class FrmrptProductRealTime extends DBCommon {

	/***
	 * 按销售组织
	 * @param list
	 * @param arr
	 * @return
	 */
	public CoreReturnObject getStorgeData(ArrayList<String> list,String[] arr)
	{
		String str = CoreConverter.toSqlConditionString("T1.BELONG_CODE", arr);
		//String str = CoreConverter.toSqlConditionStringOr("T1.BELONG_CODE", arr);
		String sql = CoreXmlSqlParsersFactory.getSql("FrmrptProductRealTime.getStorgeData").replace("#columns#", list.get(0));
		String supplyUnit = "";
		if( list.get(3).equals("120501"))
		{
			supplyUnit = " AND (T1.SUPPLY_UNIT_CODE = '"+list.get(3)+"' OR T1.SUPPLY_UNIT_CODE IS NULL)";
		}else if(list.get(3).equals("120504")){
			supplyUnit = " AND T1.SUPPLY_UNIT_CODE = '"+list.get(3)+"'";
		}
		sql = sql.replace("#conditions#", list.get(1)+supplyUnit);
		sql = sql.replace("#belongcode#", str);
		sql = sql.replace("#conditions1#", list.get(2));
		return this.getData(sql);
	}

	/***
	 * 实际库存(除去虚单一次关闭)
	 * @param list
	 * @param arr
	 * @return
	 */
	public CoreReturnObject getRealityData(ArrayList<String> list,String[] arr)
	{
		String str = CoreConverter.toSqlConditionString("T1.BELONG_CODE", arr);
		//String str1 = CoreConverter.toSqlConditionString("G.SALE_ORG", arr);
		String sql = CoreXmlSqlParsersFactory.getSql("FrmrptProductRealTime.getRealityData").replace("#columns#", list.get(3)).replace("#columns1#", list.get(0)).replace("#columns2#", list.get(5));
		String supplyUnit = "";
		if( list.get(6).equals("120501"))
		{
			supplyUnit = " AND (T1.SUPPLY_UNIT_CODE = '"+list.get(6)+"' OR T1.SUPPLY_UNIT_CODE IS NULL)";
		}else if(list.get(6).equals("120504")){
			supplyUnit = " AND T1.SUPPLY_UNIT_CODE = '"+list.get(6)+"'";
		}
		sql = sql.replace("#conditions#", list.get(1)+supplyUnit);
		sql = sql.replace("#conditions1#", str + list.get(2));
		sql = sql.replace("#conditions2#", str + list.get(4));
		return this.getData(sql);
	}
	
	/***
	 * 查询虚单量
	 * @param list
	 * @param arr
	 * @return
	 */
	public CoreReturnObject getVirtualData(ArrayList<String> list,String[] arr)
	{
		String str = CoreConverter.toSqlConditionString("T1.BELONG_CODE", arr);
		String sql = CoreXmlSqlParsersFactory.getSql("FrmrptProductRealTime.getVirtualData").replace("#columns#", list.get(0));
		String supplyUnit = "";
		if( list.get(3).equals("120501"))
		{
			supplyUnit = " AND (T1.SUPPLY_UNIT_CODE = '"+list.get(3)+"' OR T1.SUPPLY_UNIT_CODE IS NULL)";
		}else if(list.get(3).equals("120504")){
			supplyUnit = " AND T1.SUPPLY_UNIT_CODE = '"+list.get(3)+"'";
		}
		sql = sql.replace("#conditions#", list.get(1)+supplyUnit);
		sql = sql.replace("#conditions1#", str + list.get(2));
		return this.getData(sql);
	}
	/***
	 * 查询目标库库存
	 * @param list
	 * @param arr
	 * @return
	 */
	public CoreReturnObject getTargetData(ArrayList<String> list,String[] arr)
	{
		String str = CoreConverter.toSqlConditionString("T1.BELONG_CODE", arr);
		String sql = CoreXmlSqlParsersFactory.getSql("FrmrptProductRealTime.getTargetData").replace("#columns#", list.get(0));
		String supplyUnit = "";
		if( list.get(3).equals("120501"))
		{
			supplyUnit = " AND (T1.SUPPLY_UNIT_CODE = '"+list.get(3)+"' OR T1.SUPPLY_UNIT_CODE IS NULL)";
		}else if(list.get(3).equals("120504")){
			supplyUnit = " AND T1.SUPPLY_UNIT_CODE = '"+list.get(3)+"'";
		}
		sql = sql.replace("#conditions#", list.get(1)+supplyUnit);
		sql = sql.replace("#conditions1#", str + list.get(2));
		return this.getData(sql);
	}
	/***
	 * 虚单未关闭库存
	 * @param list
	 * @param arr
	 * @return
	 */
	public CoreReturnObject getNoVirtualData(ArrayList<String> list,String[] arr)
	{
		String str = CoreConverter.toSqlConditionString("T1.BELONG_CODE", arr);
		String sql = CoreXmlSqlParsersFactory.getSql("FrmrptProductRealTime.getNoVirtualData").replace("#columns#", list.get(0));
		String supplyUnit = "";
		if( list.get(3).equals("120501"))
		{
			supplyUnit = " AND (T1.SUPPLY_UNIT_CODE = '"+list.get(3)+"' OR T1.SUPPLY_UNIT_CODE IS NULL)";
		}else if(list.get(3).equals("120504")){
			supplyUnit = " AND T1.SUPPLY_UNIT_CODE = '"+list.get(3)+"'";
		}
		sql = sql.replace("#conditions#", list.get(1)+supplyUnit);
		sql = sql.replace("#conditions1#", str + list.get(2));
		return this.getData(sql);
	}
	/***
	 * 按仓库权限
	 * @param list
	 * @param arr
	 * @return
	 */
	public CoreReturnObject getStorge(ArrayList<String> list,String[] arr)
	{
		String str = CoreConverter.toSqlConditionString("T2.STORAGE_NO", arr);
		String sql = CoreXmlSqlParsersFactory.getSql("FrmrptProductRealTime.getStorgeData").replace("#columns#", list.get(0));
		//sql += CoreConverter.toSqlConditionString("T2.STORAGE_NO", arr);
		sql = sql.replace("#conditions#", list.get(1));
		sql = sql.replace("#belongcode#", str);
		sql = sql.replace("#conditions1#", str + list.get(2));
		return this.getData(sql);
		
	}
	
	/***
	 * 仓库权限
	 * @param list
	 * @param arr
	 * @return
	 */
	public CoreReturnObject getStorgeC(ArrayList<String> list,String[] arr,String flag)
	{
		String str = CoreConverter.toSqlConditionString("T2.STORAGE_NO", arr);
		String sql = CoreXmlSqlParsersFactory.getSql("FrmrptProductRealTime.getStorgeDataC").replace("#columns#", list.get(0));
		//sql = sql.replace("#conditions2#", " AND T1.BELONG_CODE IN ('"+userid+"','"+userMent+"')");
//		if(flag.equals("0"))
//		{
//			sql = sql.replace("#conditions2#", " AND T1.BELONG_CODE NOT IN ('100101','100102','100103')");
//		}else
//		{
			sql = sql.replace("#conditions2#", " AND 1=1");
//		}
		sql = sql.replace("#conditions#", list.get(1));
		sql = sql.replace("#conditions1#", str + list.get(2));
		return this.getData(sql);
		
	}
	
	/***
	 * 所属权权限
	 * @param list
	 * @param arr
	 * @return
	 */
	public CoreReturnObject getStorgeB(ArrayList<String> list,String[] arr,String flag)
	{
		String str = CoreConverter.toSqlConditionString("T1.BELONG_CODE", arr);
		String sql = CoreXmlSqlParsersFactory.getSql("FrmrptProductRealTime.getStorgeDataC").replace("#columns#", list.get(0));
		//sql = sql.replace("#conditions2#", " AND T1.BELONG_CODE IN ('"+userid+"','"+userMent+"')");
//		if(flag.equals("0"))
//		{
//			sql = sql.replace("#conditions2#", " AND T1.BELONG_CODE NOT IN ('100101','100102','100103')");
//		}else
//		{
			sql = sql.replace("#conditions2#", " AND 1=1");
//		}
		sql = sql.replace("#conditions#", list.get(1));
		sql = sql.replace("#conditions1#", str + list.get(2));
		return this.getData(sql);
		
	}


}
