package core.stlmes.server.sale.dao;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;








import CoreFS.SA06.CoreReturnObject;
import core.stlmes.server.sale.dao.*;
import core.stlmes.server.sale.po.*;

public class YdmZcLoadvehicleMatDao extends BaseService
{
	private final String Bill_no = "Bill_no";

	private core.stlmes.server.sale.dao.YdmZcBillMDao ydmZcBillMDao = null;

	public YdmZcLoadvehicleMatDao()
	{

		this.ydmZcBillMDao = new YdmZcBillMDao();
	}

	private String getSql()
	{
		String sql = "            select *  from (select LOADVEHICLE_SQE, LOADVEHICLE_NO,"
				+ "               BILL_NO,       TALLYSHEET_NO,     VEHICLE_NO,      ORDER_NO,"
				+ "               ORDER_SEQ,     ORDER_SEQ_NO,      PRO_ORDER_NO,"
				+ "               MAT_NO,        LOT_NO,            JUDGE_STOVE_NO,"
				+ "               BATCH_NO,      STOVE_NO,          MATERIAL_NO,"
				+ "               MATERIAL_NAME, PRODUCCODE,        PRODUCNAME,"
				+ "               STD_CODE,      STD_NAME,          GRADECODE,"
				+ "               GRADENAME,     STEELNAME,         STD_STYLE,"
				+ "               STD_STYLE_DESC,SPEC_CODE,         SPEC_NAME,"
				+ "               MODEL_CODE,    MODEL_DESC,        PROCESS_CDOE,"
				+ "               PROCESS_DESC,  PLINE_CODE,        PLINE_NAME,"
				+ "               ACT_DIMATER,   ACT_HEIGHT,        ACT_LEN,"
				+ "               ACT_LEN_MIN,   ACT_LEN_MAX,       sum(ACT_COUNT) over(partition by LOADVEHICLE_NO,"
				+ "               BILL_NO, TALLYSHEET_NO, ORD_PK, ORD_LN_PK, ORD_LN_DLY_PK, JUDGE_STOVE_NO, BATCH_NO,GROUP_NO) ACT_COUNT,"
				+ "               sum(ACT_WEIGHT) over(partition by LOADVEHICLE_NO, BILL_NO, TALLYSHEET_NO, ORD_PK, ORD_LN_PK, ORD_LN_DLY_PK, JUDGE_STOVE_NO, BATCH_NO,GROUP_NO) ACT_WEIGHT,"
				+ "               sum(ACT_THEORY_WEIGHT) over(partition by LOADVEHICLE_NO, BILL_NO, TALLYSHEET_NO, ORD_PK, ORD_LN_PK, ORD_LN_DLY_PK, JUDGE_STOVE_NO, BATCH_NO,GROUP_NO) ACT_THEORY_WEIGHT,"
				+ "               JUDGE_RESULT_CODE,      PRO_BC,               PRO_BZ,"
				+ "               RPO_TIME,               SEN_BC,               SEN_BZ,"
				+ "               SEN_TIME,               ZBS_BH,               SALE_ORG,"
				+ "               SALE_ORG_DESC,          SALE_AREA,            STORAGE_TYPE_NO,"
				+ "               STORAGE_TYPE_NAME,      MANAGEMENT_NO,        MANAGEMENT_NAME,"
				+ "               UPLOAD_WEB_FLAG,        STORAGE_NO,           LOCATION_NO,"
				+ "               LARY_NO,                LOC_NO,               TRANS_TPE,"
				+ "               RECEIV_NO,              RECEIV_NM,            STATION_NO,"
				+ "               STATION_NM,             SPCL_LN_NO,           SPCL_LN_NM,"
				+ "                                  PLANT,                PLANT_DESC,"
				+ "               VSTEL,                  VSTEL_DESC,           CARRY_COMPANY_CODE,"
				+ "               CARRY_COMPANY_NAME,     OUT_STOCK_CODE,       DELIVY_PLACE_CODE,"
				+ "               DELIVY_PLACE_NAME,      STLMT_UNIT_NO,        STLMT_UNIT_NM,"
				+ "               DELIVY_TIME,            MEMO,                 VALIDFLAG,"
				+ "               CREATE_NAME,            CREATE_TIME,          UPDATE_NAME,"
				+ "               UPDATE_TIME,            DELETE_NAME,          DELETE_TIME,"
				+ "               ORD_PK,                 ORD_LN_PK,            ORD_LN_DLY_PK,"
				+ "               DEPARTMENT_CODE,        DEPARTMENT_DESC,      PONDER_NO,"
				+ "               sum(nvl(PONDER_GROSS_WT,0)) over(partition by LOADVEHICLE_NO, BILL_NO, TALLYSHEET_NO, ORD_PK, ORD_LN_PK, ORD_LN_DLY_PK, JUDGE_STOVE_NO, BATCH_NO,GROUP_NO) PONDER_GROSS_WT,"
				+ "               sum(nvl(SEND_NUM,0)) over(partition by LOADVEHICLE_NO, BILL_NO, TALLYSHEET_NO, ORD_PK, ORD_LN_PK, ORD_LN_DLY_PK, JUDGE_STOVE_NO, BATCH_NO,GROUP_NO) SEND_NUM,"
				+ "               JUDGE_STD_NAME, BILL_NO_SEQ,BAL_YEAR_MONTH,GROUP_NO,"
				+ "               JUDGE_STD_CODE,      row_number() over(partition by LOADVEHICLE_NO, BILL_NO, TALLYSHEET_NO, ORD_PK, ORD_LN_PK, ORD_LN_DLY_PK, JUDGE_STOVE_NO, BATCH_NO,GROUP_NO order by LOADVEHICLE_NO, BILL_NO, TALLYSHEET_NO,"
				+ "               ORD_PK, ORD_LN_PK, ORD_LN_DLY_PK, JUDGE_STOVE_NO, BATCH_NO,GROUP_NO) rn"
				+ "               from YDM_ZC_LOADVEHICLE_MAT where 1 = 1  and  VALIDFLAG = '2') where rn = 1  ";
		return sql;
	}

	private List<YdmZcLoadVehicleMatBean> query(String sqlCondition)
			throws SQLException
	{
		List<YdmZcLoadVehicleMatBean> list = null;
		// String sqlStr =
		// " select * from YDM_ZC_LOADVEHICLE_MAT where 1 = 1  and  VALIDFLAG = '2' ";
		String sqlStr = getSql();

		sqlStr = sqlStr + sqlCondition;
		java.sql.ResultSet rs = super.executeForResult(sqlStr);
		list = YdmZcLoadVehicleMatBean.convertResultSetToBeanList(rs);
		rs.close();
		return list;
	}

	public CoreReturnObject updateYdmZcLoadVehicleMatToAccept(String billno)
			throws java.sql.SQLException,java.lang.Exception
	{
		CoreReturnObject obj = new CoreReturnObject();
		String sqlStr = " update YDM_ZC_LOADVEHICLE_MAT  set VALIDFLAG = '3' "
				+ "  where BILL_NO = ? and VALIDFLAG = '2' ";
		sqlStr = super.getPreparedSQL(sqlStr, new Object[]
		{ billno });
		obj = super.ExcuteNonQueryIgnoreTrans(sqlStr);
		return obj;

	}

	public CoreReturnObject updateYdmZcLoadVehicleMatToAccept(
			java.sql.Connection conn, String billno)
			throws java.sql.SQLException,java.lang.Exception
	{
		CoreReturnObject obj = new CoreReturnObject();
		String sqlStr = " update YDM_ZC_LOADVEHICLE_MAT  set VALIDFLAG = '3' "
				+ "  where BILL_NO = ? and VALIDFLAG = '2' ";
		sqlStr = super.getPreparedSQL(sqlStr, new Object[]
		{ billno });
		PreparedStatement ps = conn.prepareStatement(sqlStr);
		ps.executeUpdate();
		ps.close();
		return obj;

	}

	public CoreReturnObject updateYdmZcLoadVehicleMatToUnAccept(String billno)
			throws java.sql.SQLException,java.lang.Exception
	{
		CoreReturnObject obj = new CoreReturnObject();
		String sqlStr = " update YDM_ZC_LOADVEHICLE_MAT  set VALIDFLAG = '2' "
				+ "  where BILL_NO = ? and VALIDFLAG = '3' ";
		sqlStr = super.getPreparedSQL(sqlStr, new Object[]
		{ billno });
		obj = super.ExcuteNonQueryIgnoreTrans(sqlStr);
		return obj;

	}

	public String updateYdmZcLoadVehicleMatToUnAcceptSql(String billno)

	{
		CoreReturnObject obj = new CoreReturnObject();
		String sqlStr = " update YDM_ZC_LOADVEHICLE_MAT  set VALIDFLAG = '2' "
				+ "  where BILL_NO = ? and VALIDFLAG = '3' ";
		sqlStr = super.getPreparedSQL(sqlStr, new Object[]
		{ billno });
		// obj = super.ExcuteNonQueryIgnoreTrans(sqlStr);
		return sqlStr;

	}

	public List<YdmZcLoadVehicleMatBean> getYdmZcLoadvehicleMatByBillNo(
			String billNo) throws SQLException
	{

		String sqlCondition = super.GetSqlConditionByStringValue(Bill_no,
				billNo);
		return query(sqlCondition);
	}

	private final String SaleOrgOut = "";

	private String getRandomString(int length)
	{ // length表示生成字符串的长度
		String base = "abcdefghijklmnopqrstuvwxyz0123456789";
		java.util.Random random = new java.util.Random();
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < length; i++)
		{
			int number = random.nextInt(base.length());
			sb.append(base.charAt(number));
		}
		return sb.toString();
	}

	public List<SlmBalanceDetailAllBean> getSlmBalanceDetailFromLoadVehicleByBillNo(
			String billNo,java.sql.Connection conn) throws SQLException
	{
		List<SlmBalanceDetailAllBean> beanList = new ArrayList<SlmBalanceDetailAllBean>();
		YdmZcBillMNewEntity mbean = null;
		SlmOrderLineNewEntity ordBean = null;
		SlmOrderHeadNewEntity slmOrderHeadTgBean = null;
		core.stlmes.server.sale.po.SlmOrderLineDeliveryTgBean slmOrderLineDeliveryTgBean = null;
		SlmBalanceDetailAllBean de = null;
		YdmZcBillcDao ydmZcBillcDao = new YdmZcBillcDao();
		YdmZcLoadVehicleBean ydmZcLoadVehicleBean = null;

		// List<YdmZcBillMBean> listm = this.ydmZcBillMDao
		// .getCloseYdmZcBillMByBillNo(billNo);

		List<YdmZcBillMNewEntity> listm = this.ydmZcBillMDao
				.getYdmZcBillMByBillNoNew(billNo,conn);
		if (listm == null || listm.size() == 0) return null;
		// if (! (listm.get(0).getBill_status().equals("4") || listm.get(0)
		// .getIspreclose().equals("1") ))
		// {
		// return null;
		// }

		// 虚拟提单，直接返回
		if (listm.get(0).getIspreclose().equals("1")) return getVitrulSlmBalanceDetailFromLoadVehicleByBillNo(billNo);
		// if (listm.get(0).getLoadvehicle_type().equals("2")) return
		// getVitrulSlmBalanceDetailFromLoadVehicleByBillNo(billNo);

		SlmOrderLineTgDao slmOrderLineTgDao = new SlmOrderLineTgDao();
		SlmOrderHeadTgDao slmOrderHeadTgDao = new SlmOrderHeadTgDao();
		SlmOrderLineDeliveryTgDao slmOrderLineDeliveryTgDao = new SlmOrderLineDeliveryTgDao();
		YdmZcLoadVehicleDao ydmZcLoadVehicleDao = new YdmZcLoadVehicleDao();

		SlmBalanceOutStockPricCofDao slmBalanceOutStockPricCofDao = new SlmBalanceOutStockPricCofDao();

		java.util.Hashtable<String, SlmOrderLineNewEntity> hsOrder = new java.util.Hashtable<String, SlmOrderLineNewEntity>();
		java.util.Hashtable<String, SlmOrderHeadNewEntity> hsOrderHead = new java.util.Hashtable<String, SlmOrderHeadNewEntity>();
		java.util.Hashtable<String, SlmOrderLineDeliveryTgBean> hsOrderLineDeliv = new java.util.Hashtable<String, SlmOrderLineDeliveryTgBean>();
		java.util.Hashtable<String, YdmZcLoadVehicleBean> hsLoadVehicle = new java.util.Hashtable<String, YdmZcLoadVehicleBean>();
		java.util.Hashtable hsOutPrice = new java.util.Hashtable();
		// hsOutPrice = slmBalanceOutStockPricCofDao.getAllPrice();

		java.util.Hashtable hsGradeName = new java.util.Hashtable();
		// hsStorage = ydmZcBillcDao
		// .getYdmBillCStorageNoByBillnoWithKeyOrdPkAndLinePkAndDelNoPk(billNo);

		// hsGradeName = ydmZcBillcDao
		// .getYdmBillCGradeNameByBillnoWithKeyOrdPkAndLinePkAndDelNoPk(billNo);

		String orderKey = "";
		String isLockPrice = "0";
		String price_fl = "";
		int index = 0;

		for (YdmZcBillMNewEntity mbea : listm)
		{
			if (!hsOrderHead.containsKey(mbea.getOrdPk()))
			{
				slmOrderHeadTgBean = slmOrderHeadTgDao
						.getSlmOrderHeadTgByOrdPkNew(mbea.getOrdPk(),conn);
				if (slmOrderHeadTgBean == null) continue;
				hsOrderHead.put(mbea.getOrdPk(), slmOrderHeadTgBean);

				List<SlmOrderLineNewEntity> listO = slmOrderLineTgDao
						.getSlmOrderLineTgByOrdPkNew(mbea.getOrdPk(),conn);
				if (listO == null || listO.size() == 0) return null;

				for (SlmOrderLineNewEntity tgbean : listO)
				{
					orderKey = tgbean.getOrdPk() + tgbean.getOrdLnPk();
					if (!hsOrder.containsKey(orderKey))
					{
						hsOrder.put(orderKey, tgbean);
					}

				}

				java.util.List<YdmZcLoadVehicleBean> listLoad = ydmZcLoadVehicleDao
						.getYdmZcLoadVehicleByBillNo(mbea.getBillNo());
				if (listLoad == null) return null;
				for (YdmZcLoadVehicleBean vbean : listLoad)
				{
					if (!hsLoadVehicle.containsKey(vbean.getLoadvehicle_no()))
					{
						hsLoadVehicle.put(vbean.getLoadvehicle_no(), vbean);
					}

				}

				List<SlmOrderLineDeliveryTgBean> listDeliver = slmOrderLineDeliveryTgDao
						.getSlmOrderLineDeliveryByOrdPk(mbea.getOrdPk());
				if (listDeliver == null || listDeliver.size() == 0) return null;
				for (SlmOrderLineDeliveryTgBean tgbean : listDeliver)
				{
					String heKey = tgbean.getOrd_pk() + tgbean.getOrd_ln_pk()
							+ tgbean.getOrd_ln_dly_pk();
					if (!hsOrderLineDeliv.containsKey(heKey))
					{
						hsOrderLineDeliv.put(heKey, tgbean);
					}

				}

			}

		}

		List<YdmZcLoadVehicleMatBean> listMat = getYdmZcLoadvehicleMatByBillNo(billNo);
		mbean = listm.get(0);
		for (YdmZcLoadVehicleMatBean bean : listMat)
		{
			index++;

			if (!hsOrderHead.containsKey(bean.getOrd_pk()))
			{
				return null;

			}

			if (!hsOrder.containsKey(bean.getOrd_pk() + bean.getOrd_ln_pk()))
			{
				return null;
			}
			slmOrderHeadTgBean = ( SlmOrderHeadNewEntity)hsOrderHead.get(bean
					.getOrd_pk());
			ordBean = ( SlmOrderLineNewEntity)hsOrder.get(bean.getOrd_pk()
					+ bean.getOrd_ln_pk());
			slmOrderLineDeliveryTgBean = ( SlmOrderLineDeliveryTgBean)hsOrderLineDeliv
					.get(bean.getOrd_pk() + bean.getOrd_ln_pk()
							+ bean.getOrd_ln_dly_pk());
			ydmZcLoadVehicleBean = ( YdmZcLoadVehicleBean)hsLoadVehicle
					.get(bean.getLoadvehicle_no());

			de = new SlmBalanceDetailAllBean();
			price_fl = slmOrderHeadTgBean.getPriceFl();
			String pricefl = ordBean.getBalncePriceSts();
			isLockPrice = "0";
			if ("1".equals(pricefl))
			{
				isLockPrice = "1";
			}
			double price=0.0;
			if(!ordBean.getBalncePrice().equals(""))
				price=Double.parseDouble(ordBean.getBalncePrice());
			de.setOrd_price(price);
			de.setIslockprice(isLockPrice);

			if ("1".equals(pricefl)) de.setPrice(price);
			else
				de.setPrice(0.0);

			// 防止因上游序号重复问题引发的问题
			de.setPrd_id(bean.getMat_no() + "/" + getRandomString(3));
			de.setAskplan_id(bean.getBill_no());
			de.setAskplan_id_seq("001");
			de.setLoadvehicle_no(bean.getLoadvehicle_no());
			de.setTrans_car_no(bean.getVehicle_no());
			// de.setListnumber(bean.getLoadvehicle_sqe());

			de.setOrd_no(bean.getOrder_no());
			de.setOrd_seq(bean.getOrder_seq());
			de.setOrd_ln_dly(bean.getOrder_seq_no());
			// de.setBuyercode(mbean.getCustomer_no());
			// de.setBuyername(mbean.getCustomer_nm());

			// 
			de.setBuyercode(slmOrderHeadTgBean.getStlmtUnitNo());
			de.setBuyername(slmOrderHeadTgBean.getStlmtUnitNm());

			// de.setForecorpcode(mbean.getSale_org());
			// de.setForecorpname(mbean.getSale_org_desc());

			de.setForecorpcode(slmOrderHeadTgBean.getSaleOrg());
			de.setForecorpname(slmOrderHeadTgBean.getSaleOrgDesc());

			de.setSlab_no(bean.getBatch_no());
			de.setPlid(bean.getPline_name());

			de.setPrd_type("3");
			
			SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd");
			Date date=null;
			try {
				date = ft.parse(mbean.getCreateTime());
			 } catch (ParseException e) {
				 e.printStackTrace();
			 }
			//mbean.getCreateTime().substring(0,mbean.getCreateTime().lastIndexOf("."))
			String planBDate =new java.text.SimpleDateFormat("yyyyMMdd").format(date);

			// String planEDate = core.stlmes.server.sale.util.Convert
			// .getFormDateToyyyyMMdd(mbean.getPlan_end_time());
			de.setPlandate(planBDate);
			de.setPrd_roll_dtime(core.stlmes.server.sale.util.Convert
					.getFormDate(bean.getRpo_time()));
			de.setSnd_dept(bean.getSen_bz());
			de.setSnd_type("0");
			de.setSnd_dtime(bean.getDelivy_time());
			de.setSnd_location(bean.getPlant_desc());
			de.setSnd_remark(bean.getMemo());

			de.setRecv_unit(mbean.getReceivNm());
			String transType = mbean.getPlanTransType();
			String transTypeName = "";
			if (transType == null) transTypeName = "汽运";
			else if (transType.equals("110501")) transTypeName = "汽运";
			else if (transType.equals("110502")) transTypeName = "铁运";
			else if (transType.equals("110503")) transTypeName = "船舶";
			else if (transType.equals("110504")) transTypeName = "航运";

			de.setTrans_type(mbean.getPlanTransType());
			de.setTrans_type_name(transTypeName);

			// de.setMotormanname(mbean.getCarry_company_code());
			// de.setMotormanname_desc(mbean.getCarry_company_name());

			de.setMotormanname(ydmZcLoadVehicleBean.getCarry_company_code());
			de.setMotormanname_desc(ydmZcLoadVehicleBean
					.getCarry_company_name());

			de.setTran_car_type("");
			de.setStationcode(bean.getStation_no());
			de.setStationname(bean.getStation_nm());
			de.setLeasedline(bean.getSpcl_ln_no());
			de.setLeasedlinename(bean.getSpcl_ln_nm());
			de.setDelivy_place_code(bean.getDelivy_place_code());
			de.setDelivy_place_name(bean.getDelivy_place_name());
			de.setIswatercarrage("0");
			de.setLoaddock(bean.getPort());
			de.setAreacode(bean.getSale_area());
			de.setPlant(bean.getPlant());
			de.setPlant_desc(bean.getPlant_desc());

			// 如果是天津钢管国际贸易有限公司，则认为出口，只tpco对钢贸易结，不对外结算
			// if (slmOrderHeadTgBean.getFst_drawee_unit().equals("120605")) de
			// .setIsout("1");
			// else
			// de.setIsout("0");

			if ("120605".equals(slmOrderHeadTgBean.getFstDraweeUnit())) de
					.setIsout("1");
			else
				de.setIsout("0");

			de.setIsclear("0");
			de.setSpetkey(ordBean.getSpecName());
			// de.setSpetkey(bean.getAct_dimater() + "*" +
			// bean.getAct_height());
			de.setPrd_thk(bean.getAct_height() + "");
			de.setPrd_wth(bean.getAct_dimater() + "");
			de.setDiamter(bean.getAct_dimater() + "");
			de.setPrd_len(bean.getAct_len() + "");
			de.setAct_len_min(bean.getAct_len_min() + "");
			de.setAct_len_max(bean.getAct_len_max() + "");
			de.setModel_code(bean.getModel_code());
			de.setModel_desc(bean.getModel_desc());
			de.setPrd_qty(bean.getAct_count());
			de.setCal_wgt(bean.getAct_theory_weight());
			double wgt = 0.0;
			// 有过磅，取过磅
			if (bean.getPonder_gross_wt() != 0) wgt = bean.getPonder_gross_wt();
			else if  (bean.getPonder_gross_wt() == 0  && ordBean.getOrderUnit().equals("吨")  &&  bean.getSend_num() > 0)
			    wgt = bean.getSend_num();
			else			    
				wgt = bean.getAct_weight();
			de.setAct_wgt(wgt);
			de.setPd_type(bean.getProduccode());
			de.setPd_name(bean.getProducname());

			de.setSend_num(bean.getSend_num());

			// String keys = bean.getOrd_pk() + bean.getOrd_ln_pk()
			// + bean.getOrd_ln_dly_pk();
			// String catego = "";
			// if (hsGradeName.containsKey(keys))
			// {
			// catego = ( String)hsGradeName.get(keys);
			//
			// }

			de.setCategory(bean.getGradecode());
			de.setCategoryname(bean.getGradename());
			de.setSteelcode(bean.getSteelcode());
			de.setSteelname(bean.getSteelname());
			de.setSteelcodekey(bean.getSteelname());
			de.setSpec_abbsym(bean.getStd_code());
			de.setSpec_abbsymname(bean.getStd_name());
			de.setSpec_code(bean.getSpec_code());
			de.setSpec_name(bean.getSpec_name());
			de.setStatus_cd("0");
			de.setReg_dtime(core.stlmes.server.sale.util.Convert
					.getFormDate(new java.util.Date()));
			// de.setFst_drawee_unit(mbean.getFst_drawee_unit());
			de.setFst_drawee_unit(slmOrderHeadTgBean.getFstDraweeUnit());

			String isPreclose = mbean.getIspreclose();
			// String isPreclose = mbean.getLoadvehicle_type();
			de.setIspreclose("0");
			de.setBatch_no(bean.getJudge_stove_no() + "/" + bean.getBatch_no());
			de.setInv_no(bean.getGroup_no());
			de.setTallysheet_no(bean.getTallysheet_no());

			de.setOrd_pk(bean.getOrd_pk());
			de.setOrd_ln_pk(bean.getOrd_ln_pk());
			de.setOrd_ln_dly_pk(bean.getOrd_ln_dly_pk());
			de.setCreate_dept(slmOrderHeadTgBean.getCreateDept());

			// 出库费用计算，火车 23*t，汽车10*t
			// 库房 代办，算应收
			// 其他算报销

			String STORAGE_NO = bean.getStorage_no();
			String outstkPriceKey = slmOrderHeadTgBean.getSaleOrg()
					+ STORAGE_NO + transType;
			double outStkPrice = 0.0;
			// if (hsOutPrice.containsKey(outstkPriceKey))
			// {
			// outStkPrice = ( Double)hsOutPrice.get(outstkPriceKey);
			//
			// }

			String delvry_addr = slmOrderLineDeliveryTgBean.getDelvry_addr();
			String agency_fl = slmOrderLineDeliveryTgBean.getAgency_fl();
			String receiv_addr = slmOrderLineDeliveryTgBean.getReceiv_addr();
			String extraflag = slmOrderLineDeliveryTgBean.getExtra_flag();
			String[] StockMny = getOutStockMnyAndTypeWithSignalePrice(
					delvry_addr, agency_fl, receiv_addr, mbean
							.getPlanTransType(), wgt, outStkPrice, extraflag);
			de.setOutstockmny(core.stlmes.server.sale.util.Convert
					.getDouble(StockMny[0]));
			de.setMoney_type(StockMny[1]);
			de.setAgency_fl(agency_fl);
			de.setDelvry_addr(delvry_addr);
			de.setReceiv_addr(receiv_addr);

			de.setCustomer_no(slmOrderHeadTgBean.getCustomerNo());
			de.setCustomer_nm(slmOrderHeadTgBean.getCustomerNm());
			de.setSale_area_no(slmOrderHeadTgBean.getSaleAreaNo());
			de.setSale_area_desc(slmOrderHeadTgBean.getSaleAreaDesc());
			de.setOrder_unit(ordBean.getOrderUnit());
			de.setStd_style(ordBean.getStdStyle());
			de.setStd_style_desc(ordBean.getStdStyleDesc());
			de.setStorage_no(STORAGE_NO);
			de.setContain_tax(slmOrderHeadTgBean.getContainTax());
			// de.setStd_style_desc(ordBean.getStd_style_desc());

			beanList.add(de);

		}
		return beanList;

	}

	/*
	 * 处理虚拟提单
	 */
	public List<SlmBalanceDetailAllBean> getVitrulSlmBalanceDetailFromLoadVehicleByBillNo(
			String billNo) throws SQLException
	{
		if (1 == 1) return getVitrulSlmBalanceDetailFromLoadVehicleByBillNoWithBatchNo(billNo);
		List<SlmBalanceDetailAllBean> beanList = new ArrayList<SlmBalanceDetailAllBean>();
		// core.stlmes.server.sale.po.YdmZcBillMBean mbean = null;
		core.stlmes.server.sale.po.SlmOrderLineTgBean ordBean = null;
		core.stlmes.server.sale.po.SlmOrderHeadTgBean slmOrderHeadTgBean = null;
		core.stlmes.server.sale.po.SlmOrderLineDeliveryTgBean slmOrderLineDeliveryTgBean = null;
		SlmBalanceDetailAllBean de = null;
		SlmBalanceOutStockPricCofDao slmBalanceOutStockPricCofDao = new SlmBalanceOutStockPricCofDao();

		List<YdmZcBillMBean> listm = this.ydmZcBillMDao
				.getYdmZcBillMByBillNo(billNo);
		if (listm == null || listm.size() == 0) return null;

		SlmOrderLineTgDao slmOrderLineTgDao = new SlmOrderLineTgDao();
		SlmOrderHeadTgDao slmOrderHeadTgDao = new SlmOrderHeadTgDao();
		SlmOrderLineDeliveryTgDao slmOrderLineDeliveryTgDao = new SlmOrderLineDeliveryTgDao();
		YdmZcLoadVehicleDao ydmZcLoadVehicleDao = new YdmZcLoadVehicleDao();
		YdmZcBillcDao ydmZcBillcDao = new YdmZcBillcDao();
		java.util.Hashtable<String, SlmOrderLineTgBean> hsOrder = new java.util.Hashtable<String, SlmOrderLineTgBean>();
		java.util.Hashtable<String, SlmOrderHeadTgBean> hsOrderHead = new java.util.Hashtable<String, SlmOrderHeadTgBean>();
		java.util.Hashtable<String, SlmOrderLineDeliveryTgBean> hsOrderLineDeliv = new java.util.Hashtable<String, SlmOrderLineDeliveryTgBean>();
		java.util.Hashtable<String, YdmZcLoadVehicleBean> hsLoadVehicle = new java.util.Hashtable<String, YdmZcLoadVehicleBean>();

		java.util.Hashtable hsOutPrice = new java.util.Hashtable();
		// hsOutPrice = slmBalanceOutStockPricCofDao.getAllPrice();

		java.util.Hashtable hsStorage = new java.util.Hashtable();
		java.util.Hashtable hsGradeName = new java.util.Hashtable();
		// hsStorage = ydmZcBillcDao
		// .getYdmBillCStorageNoByBillnoWithKeyOrdPkAndLinePkAndDelNoPk(billNo);

		hsGradeName = ydmZcBillcDao
				.getYdmBillCGradeNameByBillnoWithKeyOrdPkAndLinePkAndDelNoPk(billNo);

		String orderKey = "";
		String isLockPrice = "1";
		String price_fl = "";
		int index = 0;

		for (YdmZcBillMBean mbea : listm)
		{
			if (!hsOrderHead.containsKey(mbea.getOrd_pk()))
			{
				slmOrderHeadTgBean = slmOrderHeadTgDao
						.getSlmOrderHeadTgByOrdPk(mbea.getOrd_pk());
				if (slmOrderHeadTgBean == null) continue;
				hsOrderHead.put(mbea.getOrd_pk(), slmOrderHeadTgBean);

				List<SlmOrderLineTgBean> listO = slmOrderLineTgDao
						.getSlmOrderLineTgByOrdPk(mbea.getOrd_pk());
				if (listO == null || listO.size() == 0) return null;

				for (SlmOrderLineTgBean tgbean : listO)
				{
					orderKey = tgbean.getOrd_pk() + tgbean.getOrd_ln_pk();
					if (!hsOrder.containsKey(orderKey))
					{
						hsOrder.put(orderKey, tgbean);
					}

				}

				List<SlmOrderLineDeliveryTgBean> listDeliver = slmOrderLineDeliveryTgDao
						.getSlmOrderLineDeliveryByOrdPk(mbea.getOrd_pk());
				if (listDeliver == null || listDeliver.size() == 0) return null;
				for (SlmOrderLineDeliveryTgBean tgbean : listDeliver)
				{
					String heKey = tgbean.getOrd_pk() + tgbean.getOrd_ln_pk()
							+ tgbean.getOrd_ln_dly_pk();
					if (!hsOrderLineDeliv.containsKey(heKey))
					{
						hsOrderLineDeliv.put(heKey, tgbean);
					}

				}

			}
			// mbean = listm.get(0);
			// if (mbea.getIspreclose().equals("1"))
			if (mbea.getLoadvehicle_type().equals("2"))
			{
				if (!hsOrderHead.containsKey(mbea.getOrd_pk()))
				{
					return null;

				}

				if (!hsOrder
						.containsKey(mbea.getOrd_pk() + mbea.getOrd_ln_pk()))
				{
					return null;
				}
				slmOrderHeadTgBean = ( SlmOrderHeadTgBean)hsOrderHead.get(mbea
						.getOrd_pk());
				ordBean = ( SlmOrderLineTgBean)hsOrder.get(mbea.getOrd_pk()
						+ mbea.getOrd_ln_pk());
				slmOrderLineDeliveryTgBean = ( SlmOrderLineDeliveryTgBean)hsOrderLineDeliv
						.get(mbea.getOrd_pk() + mbea.getOrd_ln_pk()
								+ mbea.getOrd_ln_dly_pk());

				de = new SlmBalanceDetailAllBean();
				price_fl = slmOrderHeadTgBean.getPrice_fl();

				// 牌价,非锁价
				if ("120303".equals(price_fl))
				{
					isLockPrice = "0";

				}

				de.setOrd_price(ordBean.getOrder_price());
				de.setIslockprice(isLockPrice);

				if ("1".equals(ordBean.getBalnce_price_sts()))
				{
					de.setPrice(ordBean.getBalnce_price());
				}
				else
					de.setPrice(0.0);
				// 防止因上游序号重复问题引发的问题
				de.setPrd_id("Vi" + "/" + getRandomString(9));
				de.setAskplan_id(mbea.getBill_no());
				de.setAskplan_id_seq("001");

				de.setLoadvehicle_no("");
				de.setTrans_car_no("Virtual");
				// de.setListnumber(bean.getLoadvehicle_sqe());

				de.setOrd_no(mbea.getOrder_no());
				de.setOrd_seq(mbea.getOrder_seq());
				de.setOrd_ln_dly(mbea.getDelivery_no());
				// de.setBuyercode(mbean.getCustomer_no());
				// de.setBuyername(mbean.getCustomer_nm());

				// 
				de.setBuyercode(slmOrderHeadTgBean.getStlmt_unit_no());
				de.setBuyername(slmOrderHeadTgBean.getStlmt_unit_nm());

				// de.setForecorpcode(mbean.getSale_org());
				// de.setForecorpname(mbean.getSale_org_desc());

				de.setForecorpcode(slmOrderHeadTgBean.getSale_org());
				de.setForecorpname(slmOrderHeadTgBean.getSale_org_desc());

				de.setSlab_no("虚单");
				de.setPlid("");

				de.setPrd_type("3");
				String planBDate = core.stlmes.server.sale.util.Convert
						.getFormDateToyyyyMMdd(mbea.getCreate_time());

				// String planEDate = core.stlmes.server.sale.util.Convert
				// .getFormDateToyyyyMMdd(mbean.getPlan_end_time());
				de.setPlandate(planBDate);
				de.setPrd_roll_dtime(planBDate);
				de.setSnd_dept("");
				de.setSnd_type("0");
				de.setSnd_dtime(new java.util.Date());
				de.setSnd_location("");
				de.setSnd_remark(mbea.getMemo());

				de.setRecv_unit(mbea.getReceiv_nm());
				String transType = mbea.getPlan_trans_type();
				String transTypeName = "";
				if (transType == null) transTypeName = "汽运";
				else if (transType.equals("110501")) transTypeName = "汽运";
				else if (transType.equals("110502")) transTypeName = "火运";
				else if (transType.equals("110503")) transTypeName = "船舶";
				else if (transType.equals("110504")) transTypeName = "航运";

				de.setTrans_type(mbea.getPlan_trans_type());
				de.setTrans_type_name(transTypeName);

				// de.setMotormanname(mbean.getCarry_company_code());
				// de.setMotormanname_desc(mbean.getCarry_company_name());

				de.setMotormanname("");
				de.setMotormanname_desc("");

				de.setTran_car_type("");
				de.setStationcode(mbea.getStation_no());
				de.setStationname(mbea.getStation_nm());
				de.setLeasedline(mbea.getSpcl_ln_no());
				de.setLeasedlinename(mbea.getSpcl_ln_nm());
				de.setDelivy_place_code(mbea.getDelivy_place_code());
				de.setDelivy_place_name(mbea.getDelivy_place_name());
				de.setIswatercarrage("0");
				de.setLoaddock(mbea.getPort_no());
				de.setAreacode("");
				de.setPlant("");
				de.setPlant_desc("");

				// 如果是天津钢管国际贸易有限公司，则认为出口，只tpco对钢贸易结，不对外结算
				if ("120605".equals(slmOrderHeadTgBean.getFst_drawee_unit())) de
						.setIsout("1");
				else
					de.setIsout("0");
				de.setIsclear("0");
				de.setSpetkey(mbea.getSpec_name());
				de.setPrd_thk(ordBean.getDimater() + "");
				de.setPrd_len("");
				de.setAct_len_min("");
				de.setAct_len_max("");
				de.setModel_code(ordBean.getModel_code());
				de.setModel_desc(ordBean.getModel_desc());
				de.setPrd_qty(mbea.getPlan_num());
				de.setCal_wgt(mbea.getPlan_wt());
				de.setAct_wgt(mbea.getPlan_wt());
				de.setPd_type("");
				de.setPd_name(ordBean.getProducname());
				String keys = mbea.getOrd_pk() + mbea.getOrd_ln_pk()
						+ mbea.getOrd_ln_dly_pk();
				String catego = "";
				if (hsGradeName.containsKey(keys))
				{
					catego = ( String)hsGradeName.get(keys);

				}
				de.setCategory(catego);
				de.setCategoryname(catego);
				de.setSteelcode(mbea.getSteelcode());
				de.setSteelname(mbea.getSteelname());
				de.setSteelcodekey(mbea.getSteelname());
				de.setSpec_abbsym(mbea.getStd_code());
				de.setSpec_abbsymname(mbea.getStd_name());
				de.setSpec_code(mbea.getSpec_code());
				de.setSpec_name(mbea.getSpec_name());
				de.setStatus_cd("0");
				de.setReg_dtime(core.stlmes.server.sale.util.Convert
						.getFormDate(new java.util.Date()));
				// de.setFst_drawee_unit(mbean.getFst_drawee_unit());
				de.setFst_drawee_unit(slmOrderHeadTgBean.getFst_drawee_unit());
				// String isPreclose = mbea.getIspreclose();
				// String isPreclose = mbea.getLoadvehicle_type();
				de.setIspreclose("1");
				de.setBatch_no("Virtual");
				de.setTallysheet_no("Virtual");

				de.setOrd_pk(mbea.getOrd_pk());
				de.setOrd_ln_pk(mbea.getOrd_ln_pk());
				de.setOrd_ln_dly_pk(mbea.getOrd_ln_dly_pk());
				de.setCreate_dept(slmOrderHeadTgBean.getCreate_dept());

				// 出库费用计算，火车 23*t，汽车10*t
				// 库房 代办，算应收
				// 其他算报销

				String stoKey = mbea.getOrd_pk() + mbea.getOrd_ln_pk()
						+ mbea.getOrd_ln_dly_pk();

				String STORAGE_NO = "";
				if (hsStorage.containsKey(stoKey))
				{
					STORAGE_NO = ( String)hsStorage.get(stoKey);

				}
				String outstkPriceKey = slmOrderHeadTgBean.getSale_org()
						+ STORAGE_NO + transType;
				double outStkPrice = 0.0;
				// if (hsOutPrice.containsKey(outstkPriceKey))
				// {
				// outStkPrice = ( Double)hsOutPrice.get(outstkPriceKey);
				//
				// }

				String delvry_addr = slmOrderLineDeliveryTgBean
						.getDelvry_addr();
				String agency_fl = slmOrderLineDeliveryTgBean.getAgency_fl();
				String receiv_addr = slmOrderLineDeliveryTgBean
						.getReceiv_addr();
				String[] StockMny = getOutStockMnyAndTypeWithSignalePrice(
						delvry_addr, agency_fl, receiv_addr, mbea
								.getPlan_trans_type(), mbea.getPlan_wt(),
						outStkPrice);
				de.setOutstockmny(0.0);
				de.setMoney_type(StockMny[1]);
				de.setAgency_fl(agency_fl);
				de.setDelvry_addr(delvry_addr);
				de.setReceiv_addr(receiv_addr);

				de.setCustomer_no(slmOrderHeadTgBean.getCustomer_no());
				de.setCustomer_nm(slmOrderHeadTgBean.getCustomer_nm());
				de.setSale_area_no(slmOrderHeadTgBean.getSale_area_no());
				de.setSale_area_desc(slmOrderHeadTgBean.getSale_area_desc());
				de.setOrder_unit(ordBean.getOrder_unit());
				de.setStd_style(ordBean.getStd_style());
				de.setStd_style_desc(ordBean.getStd_style_desc());
				de.setStorage_no(STORAGE_NO);
				de.setContain_tax(slmOrderHeadTgBean.getContain_tax());
				beanList.add(de);

			}

		}

		return beanList;

	}

	public List<SlmBalanceDetailAllBean> getVitrulSlmBalanceDetailFromLoadVehicleByBillNoWithBatchNo(
			String billNo) throws SQLException
	{
		List<SlmBalanceDetailAllBean> beanList = new ArrayList<SlmBalanceDetailAllBean>();
		// core.stlmes.server.sale.po.YdmZcBillMBean mbean = null;
		core.stlmes.server.sale.po.SlmOrderLineTgBean ordBean = null;
		core.stlmes.server.sale.po.SlmOrderHeadTgBean slmOrderHeadTgBean = null;
		core.stlmes.server.sale.po.SlmOrderLineDeliveryTgBean slmOrderLineDeliveryTgBean = null;
		SlmBalanceDetailAllBean de = null;
		SlmBalanceOutStockPricCofDao slmBalanceOutStockPricCofDao = new SlmBalanceOutStockPricCofDao();

		List<YdmZcBillMBean> listm = this.ydmZcBillMDao
				.getYdmZcBillMByBillNo(billNo);
		if (listm == null || listm.size() == 0) return null;

		SlmOrderLineTgDao slmOrderLineTgDao = new SlmOrderLineTgDao();
		SlmOrderHeadTgDao slmOrderHeadTgDao = new SlmOrderHeadTgDao();
		SlmOrderLineDeliveryTgDao slmOrderLineDeliveryTgDao = new SlmOrderLineDeliveryTgDao();
		YdmZcLoadVehicleDao ydmZcLoadVehicleDao = new YdmZcLoadVehicleDao();
		YdmZcBillcDao ydmZcBillcDao = new YdmZcBillcDao();
		java.util.Hashtable<String, SlmOrderLineTgBean> hsOrder = new java.util.Hashtable<String, SlmOrderLineTgBean>();
		java.util.Hashtable<String, SlmOrderHeadTgBean> hsOrderHead = new java.util.Hashtable<String, SlmOrderHeadTgBean>();
		java.util.Hashtable<String, SlmOrderLineDeliveryTgBean> hsOrderLineDeliv = new java.util.Hashtable<String, SlmOrderLineDeliveryTgBean>();
		java.util.Hashtable<String, YdmZcLoadVehicleBean> hsLoadVehicle = new java.util.Hashtable<String, YdmZcLoadVehicleBean>();

		java.util.Hashtable hsOutPrice = new java.util.Hashtable();
		// hsOutPrice = slmBalanceOutStockPricCofDao.getAllPrice();

		java.util.Hashtable hsStorage = new java.util.Hashtable();
		java.util.Hashtable hsGradeName = new java.util.Hashtable();
		java.util.Hashtable hsBatchNo = new java.util.Hashtable();
		java.util.Hashtable hsBatchNoAndWgt = new java.util.Hashtable();
		// hsStorage = ydmZcBillcDao
		// .getYdmBillCStorageNoByBillnoWithKeyOrdPkAndLinePkAndDelNoPk(billNo);

		hsGradeName = ydmZcBillcDao
				.getYdmBillCGradeNameByBillnoWithKeyOrdPkAndLinePkAndDelNoPk(billNo);
		hsBatchNo = ydmZcBillcDao
				.getYdmBillBatchNoByBillnoWithKeyOrdPkAndLinePkAndDelNoPk(billNo);

		String orderKey = "";
		String isLockPrice = "1";
		String price_fl = "";
		int index = 0;

		for (YdmZcBillMBean mbea : listm)
		{
			if (!hsOrderHead.containsKey(mbea.getOrd_pk()))
			{
				slmOrderHeadTgBean = slmOrderHeadTgDao
						.getSlmOrderHeadTgByOrdPk(mbea.getOrd_pk());
				if (slmOrderHeadTgBean == null) continue;
				hsOrderHead.put(mbea.getOrd_pk(), slmOrderHeadTgBean);

				List<SlmOrderLineTgBean> listO = slmOrderLineTgDao
						.getSlmOrderLineTgByOrdPk(mbea.getOrd_pk());
				if (listO == null || listO.size() == 0) return null;

				for (SlmOrderLineTgBean tgbean : listO)
				{
					orderKey = tgbean.getOrd_pk() + tgbean.getOrd_ln_pk();
					if (!hsOrder.containsKey(orderKey))
					{
						hsOrder.put(orderKey, tgbean);
					}

				}

				List<SlmOrderLineDeliveryTgBean> listDeliver = slmOrderLineDeliveryTgDao
						.getSlmOrderLineDeliveryByOrdPk(mbea.getOrd_pk());
				if (listDeliver == null || listDeliver.size() == 0) return null;
				for (SlmOrderLineDeliveryTgBean tgbean : listDeliver)
				{
					String heKey = tgbean.getOrd_pk() + tgbean.getOrd_ln_pk()
							+ tgbean.getOrd_ln_dly_pk();
					if (!hsOrderLineDeliv.containsKey(heKey))
					{
						hsOrderLineDeliv.put(heKey, tgbean);
					}

				}

			}
			// mbean = listm.get(0);
			// if (mbea.getIspreclose().equals("1"))
			if (mbea.getLoadvehicle_type().equals("2"))
			{
				if (!hsOrderHead.containsKey(mbea.getOrd_pk()))
				{
					return null;

				}

				if (!hsOrder
						.containsKey(mbea.getOrd_pk() + mbea.getOrd_ln_pk()))
				{
					return null;
				}
				slmOrderHeadTgBean = ( SlmOrderHeadTgBean)hsOrderHead.get(mbea
						.getOrd_pk());
				ordBean = ( SlmOrderLineTgBean)hsOrder.get(mbea.getOrd_pk()
						+ mbea.getOrd_ln_pk());
				slmOrderLineDeliveryTgBean = ( SlmOrderLineDeliveryTgBean)hsOrderLineDeliv
						.get(mbea.getOrd_pk() + mbea.getOrd_ln_pk()
								+ mbea.getOrd_ln_dly_pk());
				String ordPk = mbea.getOrd_pk();
				String ordLnpk = mbea.getOrd_ln_pk();
				String ordLnDpk = mbea.getOrd_ln_dly_pk();

				hsBatchNoAndWgt = ( java.util.Hashtable)hsBatchNo.get(ordPk
						+ ordLnpk + ordLnDpk + billNo);

				java.util.Set set = hsBatchNoAndWgt.keySet();
				Object[] obj = set.toArray();
				for (Object o : obj)
				{
					String[] temp = ( String[])hsBatchNoAndWgt
							.get(o.toString());
					String batNO = temp[0];
					String pno = temp[1];
					String groupNO = temp[4];
					Double wght = core.stlmes.server.sale.util.Convert
							.getDouble(temp[2]);
					Double qty = core.stlmes.server.sale.util.Convert
							.getDouble(temp[3]);

					de = new SlmBalanceDetailAllBean();

					price_fl = slmOrderHeadTgBean.getPrice_fl();

					// 牌价,非锁价
					if ("120303".equals(price_fl))
					{
						isLockPrice = "0";

					}

					de.setOrd_price(ordBean.getOrder_price());
					de.setIslockprice(isLockPrice);

					if ("1".equals(ordBean.getBalnce_price_sts()))
					{
						de.setPrice(ordBean.getBalnce_price());
					}
					else
						de.setPrice(0.0);
					// 防止因上游序号重复问题引发的问题
					de.setPrd_id("Vi" + "/" + getRandomString(9));
					de.setAskplan_id(mbea.getBill_no());
					de.setAskplan_id_seq("001");

					de.setLoadvehicle_no("");
					de.setTrans_car_no("Virtual");
					// de.setListnumber(bean.getLoadvehicle_sqe());

					de.setOrd_no(mbea.getOrder_no());
					de.setOrd_seq(mbea.getOrder_seq());
					de.setOrd_ln_dly(mbea.getDelivery_no());
					// de.setBuyercode(mbean.getCustomer_no());
					// de.setBuyername(mbean.getCustomer_nm());

					// 
					de.setBuyercode(slmOrderHeadTgBean.getStlmt_unit_no());
					de.setBuyername(slmOrderHeadTgBean.getStlmt_unit_nm());

					// de.setForecorpcode(mbean.getSale_org());
					// de.setForecorpname(mbean.getSale_org_desc());

					de.setForecorpcode(slmOrderHeadTgBean.getSale_org());
					de.setForecorpname(slmOrderHeadTgBean.getSale_org_desc());

					de.setSlab_no("虚单");
					de.setPlid("");

					de.setPrd_type("3");
					String planBDate = core.stlmes.server.sale.util.Convert
							.getFormDateToyyyyMMdd(mbea.getCreate_time());

					// String planEDate = core.stlmes.server.sale.util.Convert
					// .getFormDateToyyyyMMdd(mbean.getPlan_end_time());
					de.setPlandate(planBDate);
					de.setPrd_roll_dtime(planBDate);
					de.setSnd_dept("");
					de.setSnd_type("0");
					de.setSnd_dtime(new java.util.Date());
					de.setSnd_location("");
					de.setSnd_remark(mbea.getMemo());

					de.setRecv_unit(mbea.getReceiv_nm());
					String transType = mbea.getPlan_trans_type();
					String transTypeName = "";
					if (transType == null) transTypeName = "汽运";
					else if (transType.equals("110501")) transTypeName = "汽运";
					else if (transType.equals("110502")) transTypeName = "火运";
					else if (transType.equals("110503")) transTypeName = "船舶";
					else if (transType.equals("110504")) transTypeName = "航运";

					de.setTrans_type(mbea.getPlan_trans_type());
					de.setTrans_type_name(transTypeName);

					// de.setMotormanname(mbean.getCarry_company_code());
					// de.setMotormanname_desc(mbean.getCarry_company_name());

					de.setMotormanname("");
					de.setMotormanname_desc("");

					de.setTran_car_type("");
					de.setStationcode(mbea.getStation_no());
					de.setStationname(mbea.getStation_nm());
					de.setLeasedline(mbea.getSpcl_ln_no());
					de.setLeasedlinename(mbea.getSpcl_ln_nm());
					de.setDelivy_place_code(mbea.getDelivy_place_code());
					de.setDelivy_place_name(mbea.getDelivy_place_name());
					de.setIswatercarrage("0");
					de.setLoaddock(mbea.getPort_no());
					de.setAreacode("");
					de.setPlant("");
					de.setPlant_desc("");

					// 如果是天津钢管国际贸易有限公司，则认为出口，只tpco对钢贸易结，不对外结算
					if ("120605"
							.equals(slmOrderHeadTgBean.getFst_drawee_unit())) de
							.setIsout("1");
					else
						de.setIsout("0");
					de.setIsclear("0");
					de.setSpetkey(mbea.getSpec_name());
					de.setPrd_thk(ordBean.getDimater() + "");
					de.setPrd_len("");
					de.setAct_len_min("");
					de.setAct_len_max("");
					de.setModel_code(ordBean.getModel_code());
					de.setModel_desc(ordBean.getModel_desc());

					de.setPrd_qty(mbea.getPlan_num());
					de.setCal_wgt(mbea.getPlan_wt());
					de.setAct_wgt(mbea.getPlan_wt());

					de.setPrd_qty(qty);
					de.setCal_wgt(wght);
					de.setAct_wgt(wght);

					de.setPd_type("");
					de.setPd_name(ordBean.getProducname());
					String keys = mbea.getOrd_pk() + mbea.getOrd_ln_pk()
							+ mbea.getOrd_ln_dly_pk();
					String catego = "";
					if (hsGradeName.containsKey(keys))
					{
						catego = ( String)hsGradeName.get(keys);

					}
					de.setCategory(catego);
					de.setCategoryname(catego);
					de.setSteelcode(mbea.getSteelcode());
					de.setSteelname(mbea.getSteelname());
					de.setSteelcodekey(mbea.getSteelname());
					de.setSpec_abbsym(mbea.getStd_code());
					de.setSpec_abbsymname(mbea.getStd_name());
					de.setSpec_code(mbea.getSpec_code());
					de.setSpec_name(mbea.getSpec_name());
					de.setStatus_cd("0");
					de.setReg_dtime(core.stlmes.server.sale.util.Convert
							.getFormDate(new java.util.Date()));
					// de.setFst_drawee_unit(mbean.getFst_drawee_unit());
					de.setFst_drawee_unit(slmOrderHeadTgBean
							.getFst_drawee_unit());
					// String isPreclose = mbea.getIspreclose();
					// String isPreclose = mbea.getLoadvehicle_type();
					de.setIspreclose("1");
					de.setBatch_no("Virtual");
					de.setTallysheet_no("Virtual");

					de.setBatch_no(batNO + "/" + pno);

					de.setOrd_pk(mbea.getOrd_pk());
					de.setOrd_ln_pk(mbea.getOrd_ln_pk());
					de.setOrd_ln_dly_pk(mbea.getOrd_ln_dly_pk());
					de.setCreate_dept(slmOrderHeadTgBean.getCreate_dept());

					// 出库费用计算，火车 23*t，汽车10*t
					// 库房 代办，算应收
					// 其他算报销

					String stoKey = mbea.getOrd_pk() + mbea.getOrd_ln_pk()
							+ mbea.getOrd_ln_dly_pk();

					String STORAGE_NO = "";
					if (hsStorage.containsKey(stoKey))
					{
						STORAGE_NO = ( String)hsStorage.get(stoKey);

					}
					String outstkPriceKey = slmOrderHeadTgBean.getSale_org()
							+ STORAGE_NO + transType;
					double outStkPrice = 0.0;
					// if (hsOutPrice.containsKey(outstkPriceKey))
					// {
					// outStkPrice = ( Double)hsOutPrice.get(outstkPriceKey);
					//
					// }

					String delvry_addr = slmOrderLineDeliveryTgBean
							.getDelvry_addr();
					String agency_fl = slmOrderLineDeliveryTgBean
							.getAgency_fl();
					String receiv_addr = slmOrderLineDeliveryTgBean
							.getReceiv_addr();
					String[] StockMny = getOutStockMnyAndTypeWithSignalePrice(
							delvry_addr, agency_fl, receiv_addr, mbea
									.getPlan_trans_type(), mbea.getPlan_wt(),
							outStkPrice);
					de.setOutstockmny(0.0);
					de.setMoney_type(StockMny[1]);
					de.setAgency_fl(agency_fl);
					de.setDelvry_addr(delvry_addr);
					de.setReceiv_addr(receiv_addr);

					de.setCustomer_no(slmOrderHeadTgBean.getCustomer_no());
					de.setCustomer_nm(slmOrderHeadTgBean.getCustomer_nm());
					de.setSale_area_no(slmOrderHeadTgBean.getSale_area_no());
					de
							.setSale_area_desc(slmOrderHeadTgBean
									.getSale_area_desc());
					de.setOrder_unit(ordBean.getOrder_unit());
					de.setStd_style(ordBean.getStd_style());
					de.setStd_style_desc(ordBean.getStd_style_desc());
					de.setStorage_no(STORAGE_NO);
					de.setContain_tax(slmOrderHeadTgBean.getContain_tax());

					de.setInv_no(groupNO);
					beanList.add(de);

				}
			}

		}

		return beanList;

	}

	// delvry_addr 交货地点
	// agency_fl 代办标志
	// receiv_addr 指定地点
	public String[] getOutStockMnyAndType(String delvry_addr, String agency_fl,
			String receiv_addr, String transType, double weight,
			String isPreclose)
	{

		String[] str = new String[]
		{ "0", "0" };
		double mny = 0;
		String mnyType = "报销";

		if (isPreclose.equals("2"))
		{
			str[1] = "";
			return str;

		}

		if (delvry_addr.equals("TPCO库房") && agency_fl.equals("1"))
		{
			mnyType = "应收";
			mny = getOutStockMny(transType, weight);

		}

		if (!delvry_addr.equals("TPCO库房"))
		{
			mnyType = "报销";
			mny = getOutStockMny(transType, weight);

		}
		str[0] = mny + "";
		str[1] = mnyType;

		return str;
	}

	public String[] getOutStockMnyAndTypeWithSignalePrice(String delvry_addr,
			String agency_fl, String receiv_addr, String transType,
			double weight, double price)
	{
		String[] str = new String[]
		{ "0", "0" };

		// 火车出库费直接为不含税19.83，汽车8.62

		double signalePrice = 19.83;

		if ("110501".equals(transType))
		{
			signalePrice = 8.62;

		}

		double mny = 0;
		String mnyType = "无";
		// if (delvry_addr.equals("TPCO库房") && agency_fl.equals("1"))
		// {
		// mnyType = "应收";
		// mny = weight * price;
		// str[0] = mny + "";
		// str[1] = mnyType;
		// return str;
		//
		// }

		if ("TPCO库房".equals(delvry_addr) && "1".equals(agency_fl))
		{
			mnyType = "应收";
			mny = weight * signalePrice;
			str[0] = mny + "";
			str[1] = mnyType;
			return str;

		}

		if ("TPCO库房".equals(delvry_addr) && "0".equals(agency_fl))
		{
			mnyType = "无";
			mny = 0;
			str[0] = mny + "";
			str[1] = mnyType;
			return str;

		}

		if ("TPCO库房车板".equals(delvry_addr) || "指定地点".equals(delvry_addr))
		{
			mnyType = "报销";
			mny = weight * signalePrice;
			str[0] = mny + "";
			str[1] = mnyType;
			return str;

		}
		// 其他都算目标库，无出库费用
		if (! ("TPCO库房车板".equals(delvry_addr) || "指定地点".equals(delvry_addr) )
				&& "0".equals(agency_fl))
		{
			mnyType = "无";
			mny = 0;
			str[0] = mny + "";
			str[1] = mnyType;
			return str;

		}

		str[0] = mny + "";
		str[1] = mnyType;

		return str;

	}

	public String[] getOutStockMnyAndTypeWithSignalePrice(String delvry_addr,
			String agency_fl, String receiv_addr, String transType,
			double weight, double price, String extra_flag)
	{
		String[] str = new String[]
		{ "0", "0" };

		// 火车出库费直接为不含税19.83，汽车8.62

		double signalePrice = 19.83;

		if ("110501".equals(transType))
		{
			signalePrice = 8.62;

		}

		double mny = 0;
		String mnyType = "无";
		// 有另加出库费的，直接算应收
		if ("1".equals(extra_flag))
		{
			mnyType = "应收";
			mny = weight * signalePrice;
			str[0] = mny + "";
			str[1] = mnyType;
			return str;

		}

		if ("TPCO库房".equals(delvry_addr) && "1".equals(agency_fl))
		{
			mnyType = "应收";
			mny = weight * signalePrice;
			str[0] = mny + "";
			str[1] = mnyType;
			return str;

		}

		if ("TPCO库房".equals(delvry_addr) && "0".equals(agency_fl))
		{
			mnyType = "无";
			mny = 0;
			str[0] = mny + "";
			str[1] = mnyType;
			return str;

		}

		if ("TPCO库房车板".equals(delvry_addr) || "指定地点".equals(delvry_addr))
		{
			mnyType = "报销";
			mny = weight * signalePrice;
			str[0] = mny + "";
			str[1] = mnyType;
			return str;

		}
		// 其他都算目标库，无出库费用
		if (! ("TPCO库房车板".equals(delvry_addr) || "指定地点".equals(delvry_addr) )
				&& "0".equals(agency_fl))
		{
			mnyType = "无";
			mny = 0;
			str[0] = mny + "";
			str[1] = mnyType;
			return str;

		}

		str[0] = mny + "";
		str[1] = mnyType;

		return str;

	}

	public String[] getOutStockMnyAndTypeds(String delvry_addr,
			String agency_fl, String receiv_addr, String transType,
			double weight)
	{
		String[] str = new String[]
		{ "0", "0" };
		double mny = 0;
		String mnyType = "报销";

		if (delvry_addr.equals("TPCO库房") && agency_fl.equals("1"))
		{
			mnyType = "应收";
			mny = getOutStockMny(transType, weight);

		}

		if (delvry_addr.equals("TPCO库房车板") || delvry_addr.equals("指定地点"))
		{
			mnyType = "报销";
			mny = getOutStockMny(transType, weight);

		}
		str[0] = mny + "";
		str[1] = mnyType;
		return str;
	}

	private double getOutStockMny(String transType, double weight)
	{
		if (weight == 0) return 0;
		if ("110501".equals(transType))
		{
			return 10 * weight;

		}
		if ("110502".equals(transType))
		{
			return 23 * weight;

		}
		return 0;

	}

}
