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 FrmrptProductSendOut extends DBCommon{
	
	/***
	 * 按销售组织
	 * @param list
	 * @param arr
	 * @return
	 */
	public CoreReturnObject getSendOutData(ArrayList<String> list,String[] arr)
	{
		return getSendOutData(list,arr,null);
	}
     public CoreReturnObject getSendOutData(ArrayList<String> list,String[] arr,String[] depts)
     {
    	 String sql = CoreXmlSqlParsersFactory.getSql("FrmrptProductSendOut.getSendOutData").replace("#columns#", list.get(0));
    	 //2025年3月14日，去掉所属销售组织的限制
    	 //sql +=CoreConverter.toSqlConditionString("T.SALE_ORG", arr);
		 String supplyUnit = "";
		 if( list.get(3).equals("120501"))
		 {
			 supplyUnit = " AND (M.SUPPLY_UNIT = '"+list.get(3)+"' OR M.SUPPLY_UNIT IS NULL)";
		 }else if(list.get(3).equals("120504")){
			 supplyUnit = " AND M.SUPPLY_UNIT = '"+list.get(3)+"'";
		 }
		 if(depts!=null && depts.length >0){
			 sql += CoreConverter.toSqlConditionString("G.CREATE_DEPT",depts);
		 }
 		sql = sql.replace("#conditions#", list.get(1)+supplyUnit);
 		sql = sql + list.get(2);
 		return this.getData(sql); 
     }
     
     public CoreReturnObject getSendOut(ArrayList<String> list,String[] arr)
     {
    	 String sql = CoreXmlSqlParsersFactory.getSql("FrmrptProductSendOut.getSendOutData").replace("#columns#", list.get(0));
    	 //2025-3-15，去掉权限配置
    	 // sql +=CoreConverter.toSqlConditionString("d.STORAGE_NO", arr);
 		sql = sql.replace("#conditions#", list.get(1));
 		sql = sql + list.get(2);
 		return this.getData(sql);
     }
     /***
      * 仓库权限
      * @param list
      * @param arr
      * @param userid
      * @param userMent
      * @return
      */
     public CoreReturnObject getSendOutC(ArrayList<String> list,String[] arr,String flag,String outFlag)
     {
    	 String sql = CoreXmlSqlParsersFactory.getSql("FrmrptProductSendOut.getSendOutDataC").replace("#columns#", list.get(0)).replace("#TAR_REC_FLAG#", outFlag);
    	 sql +=CoreConverter.toSqlConditionString("d.STORAGE_NO", arr);
    	 if(outFlag.equals("0"))
    	 {
    		 sql = sql.replace("#conditions1#", " AND 1=1)");
    	 }else
    	 {
    		 sql = sql.replace("#conditions1#", " OR T.OUTSTOCK_TYPE_CODE = '800805')");
    	 }
 		 sql = sql.replace("#conditions#", list.get(1));
 		 sql = sql + list.get(2);
 		return this.getData(sql);
     }
     
     /***
      * 所属权权限
      * @param list
      * @param arr
      * @param userid
      * @param userMent
      * @return
      */
     public CoreReturnObject getSendOutB(ArrayList<String> list,String[] arr,String flag)
     {
    	 String sql = CoreXmlSqlParsersFactory.getSql("FrmrptProductSendOut.getSendOutDataB").replace("#columns#", list.get(0));
    	 sql +=CoreConverter.toSqlConditionString("T.BELONG_CODE", arr);
//    	 if(flag.equals("0"))
//    	 {
//    		 sql = sql.replace("#conditions1#", " AND T.BELONG_CODE NOT IN ('100101', '100102', '100103')");
//    	 }else
//    	 {
    		 sql = sql.replace("#conditions1#", " AND 1=1");
//    	 }
 		 sql = sql.replace("#conditions#", list.get(1));
 		 sql = sql + list.get(2);
 		return this.getData(sql);
     }
}
