package com.app.hxqh.udlld;


import psdi.mbo.MAXTableDomain;
import psdi.mbo.MboRemote;
import psdi.mbo.MboSetRemote;
import psdi.mbo.MboValue;
import psdi.util.MXException;

import java.rmi.RemoteException;

/**
 * 领料申请单/车辆领料申请单 选择车间
 * edit 20240923
 */
public class FldWorkshop extends MAXTableDomain{

	public FldWorkshop(MboValue mbv) {
		super(mbv);
		String thisAttr = getMboValue().getAttributeName();
		setRelationship("DEPT", "");
		String[] FromStr = { "DEPTNUM" };
		String[] ToStr = { thisAttr };
		setLookupKeyMapInOrder(ToStr, FromStr);
	}

	public MboSetRemote getList() throws MXException, RemoteException {
		MboSetRemote set = super.getList();
		MboRemote mbo=getMboValue().getMbo();
		String siteid=mbo.getString("SITEID");
//		String appName = mbo.getThisMboSet().getApp();
//		String langcode=mbo.getUserInfo().getLangCode();
//		if("".equalsIgnoreCase(appName)) { //
			set.setWhere(" SITEID='"+siteid+"' AND DEPTNUM in(SELECT WHS_LOCATION_CODE FROM UDCBZXYDLXYS WHERE SITEID='"+siteid+"' ) ");
			set.reset();
//		}
		return set;
	}

	@Override
	public void action() throws MXException, RemoteException {
		super.action();
		MboRemote mbo=getMboValue().getMbo();
		String siteid=mbo.getString("SITEID");
		String deptnum=mbo.getString("WORKSHOP");
		//赋值车间主管
		MboSetRemote deptSet=mbo.getMboSet("$DEPT","DEPT","SITEID='"+siteid+"' AND DEPTNUM='"+deptnum+"' ");
		if(null!=deptSet && !deptSet.isEmpty()){
			mbo.setValue("UDZGR", deptSet.getMbo(0).getString("DIRECTOR"),11L);
        }

		//赋值成本中心
		MboSetRemote bmcbzxSet=mbo.getMboSet("$UDCBZXYDLXYS","UDCBZXYDLXYS","SITEID='"+siteid+"' AND WHS_LOCATION_CODE='"+deptnum+"'");
		if(null!=bmcbzxSet && !bmcbzxSet.isEmpty()){
			if(bmcbzxSet.count()<=1){
				String centerCost = bmcbzxSet.getMbo(0).getString("COST_CENTER");//成本中心
				mbo.setValue("KOSTL",centerCost,2L);
			}
		}

	}


}

 



