package com.app.hxqh.udRecovery;

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

import java.rmi.RemoteException;

/**
 * 旧件回收明细-从旧件回收清单中选择物料编号
 * createby liuxq 2023-6-17
 */
public class FldItemnum extends MAXTableDomain {

    public FldItemnum(MboValue mbv) throws MXException,RemoteException {
        super(mbv);
        String thisAttr = getMboValue().getAttributeName();
        setRelationship("UDRECLIST", "");//从资产表弹出选择的表
        String[] FromStr = { "ITEMNUM" };
        String[] ToStr = { thisAttr };
        setLookupKeyMapInOrder(ToStr, FromStr);
    }

    public void init() throws RemoteException, MXException {
        super.init();
    }
    public void action() throws RemoteException, MXException {
        super.action();
        MboRemote mbo = getMboValue().getMbo();
        MboRemote owner = mbo.getOwner();//父级对象
        String ORGID = mbo.getString("ORGID");
        String SITEID = mbo.getString("SITEID");
        String WONUM = owner.getString("WONUM");//领料申请单
        String itemnum = mbo.getString("ITEMNUM");
        Integer UDLLDID = null;
        MboSetRemote udlldSet = MXServer.getMXServer().getMboSet("UDLLD",MXServer.getMXServer().getSystemUserInfo());//人员表
        udlldSet.setWhere(" WONUM='"+WONUM+"' AND ORGID='"+ORGID+"' AND SITEID='"+SITEID+"'");
        udlldSet.reset();
        if(udlldSet!=null && !udlldSet.isEmpty()){
            MboRemote udlldMbo = udlldSet.getMbo(0);
            UDLLDID = udlldMbo.getInt("UDLLDID");
        }
        MboSetRemote udlldLineSet = MXServer.getMXServer().getMboSet("UDLLDLINE",MXServer.getMXServer().getSystemUserInfo());//人员表
        udlldLineSet.setWhere("ITEMNUM='"+itemnum+"' and parentid="+UDLLDID+"");
        udlldLineSet.reset();
        if(udlldLineSet!=null && !udlldLineSet.isEmpty()){
           MboRemote udlldLineMbo = udlldLineSet.getMbo(0);
           Double ORDERQTY = udlldLineMbo.getDouble("ORDERQTY");
            mbo.setValue("YYNUM",ORDERQTY,11L);
        }
    }

    public MboSetRemote getList() throws RemoteException, MXException {
        MboRemote mbo = getMboValue().getMbo();
        String ORGID = mbo.getString("ORGID");
        String SITEID = mbo.getString("SITEID");
        MboRemote owner = mbo.getOwner();//父级对象
        String WONUM = owner.getString("WONUM");//领料申请单
        String sql = "" ;
        if(WONUM!=null && !"".equals(WONUM)){
            sql = " ITEMNUM IN(SELECT ITEMNUM FROM UDLLDLINE WHERE PARENTID=(SELECT UDLLDID FROM UDLLD WHERE WONUM='"+WONUM+"' AND ORGID='"+ORGID+"' AND SITEID='"+SITEID+"'))";
        }else{
            sql = " 1=1 and ORGID='"+ORGID+"' and SITEID='"+SITEID+"'";
        }
        setListCriteria(sql);
        return super.getList();
    }
}