NC6 转库单、采购入库单、库存委托入库单签字后自动生成调拨订单

需求方案:

一、业务逻辑
1.业务背景
某集团计划将采购职能(转库单、采购、委外业务)集中到某个业务单元中,形成集团采购中心。所有具有对外销售职能的业务单元的供应需求,都由该采购中心供货。为加速业务流转、减少人工操作,该集团希望通过客开实现入库(转库单保存签字、采购入库单签字、委托加工入库单签字)自动驱动成品对销售业务单元的内部调拨。
2.业务逻辑
【转库单】保存签字而【采购入库单】、【委外入库单】签字时,如果单据表头仓库档案配置了“对方库存组织”、“对方仓库”,且上游【采购订单】、【委外订单】的交易类型参数“自动内部调拨”为“是”,则生成“入库库存组织”对“对方库存组织”的【调拨订单】。【调拨订单】交易类型由组织级参数“入库触发调拨单交易类型”设定。生成的【调拨订单】,根据组织级参数“入库触发调拨单状态”决定是否自动审核。

二、开发需求
1.仓库档案
在仓库档案通过自定义项6、自定义项7,设置自动形成内部调拨业务单据时的“对方库存组织”、“对方仓库”。其中:

  1. 对方库存组织:在具有“库存职能”的业务单元中任选其一,不包含已停用的;
  2. 对方仓库:仓库档案中“所属库存组织”属于“对方库存组织”的所有未停用仓库任选其一;
  3. 编辑仓库档案时,允许修改“对方库存组织”、“对方仓库”,也允许清空。如果修改了“对方库存组织”(含清空),则清空“对方仓库”;
  4. 保存时,如果“对方库存组织”有值,但“对方仓库”为空,则提示“已配置“对方库存组织”,但未配置“对方仓库”,无法自动调拨”,允许保存;
    在这里插入图片描述

2.交易类型参数
【库存其他入库单】、【采购入库】、【委托加工入库单】交易类型增加“自动内部调拨”参数,可勾选或反选。(动态建模平台->流程管理->交易类型管理)
注:该参数需要在代码中添加实现
在这里插入图片描述在这里插入图片描述
在这里插入图片描述

3.组织级参数
系统按照下表增加两个组织级参数:
在这里插入图片描述
在【参数模板设置】中添加上面表格的参数,添加完后升级组织参数:
在这里插入图片描述

4.入库单签字改造
【采购入库单】、【委外入库单】签字时:

  1. 如果入库实收数量为负,则结束;
  2. 如果上游【采购订单】、【委外订单】交易类型“自动内部调拨”参数为“否”,则结束;
  3. 如果本组织的组织级系统参数“采购入库触发调拨单交易类型”、“委外入库触发调拨单交易类型”为空,则提示“参数IC205“采购入库触发调拨单交易类型”未配置,不能自动调拨”、“参数IC207“委外入库触发调拨单交易类型”未配置,不能自动调拨”,并结束;
  4. 如果【采购入库单】、【委外入库单】表头仓库档案自定义项4“对方库存组织”为空,则结束;
  5. 如果【采购入库单】、【委外入库单】表头仓库档案自定义项5“对方仓库”为空则提示“已配置“对方库存组织”,但未配置“对方仓库”,无法自动调拨”,并结束;
  6. 生成【调拨订单】。【调拨订单】的“调出库存组织”、“调出仓库”与入库单的“库存组织”、“入库仓库”保持一致,“调入库存组织”、“调入仓库”与入库单入库仓库档案的“对方库存组织”(自定义项4)、“对方仓库”(自定义项5)保持一致。物料明细行与入库单的物料明细行保持一致(只保留实收数大于零的行),且单位、数量、主单位、主数量与入库单各行的单位、实收数量、主单位、实收主数量保持一致。每一明细行物料按照系统 “内部结算规则”,形成调拨订单价格(税率、无税单价、含税单价、无税金额、价税合计)。;
  7. 本组织组织级参数“采购入库触发调拨单状态”、“委外入库触发调拨单状态”为“自由”,则结束;
  8. 触发【调拨订单】“审核”;
    在这里插入图片描述

5.入库单取消签字改造
【采购入库单】、【委外入库单】取消签字时,如果入库单存在下游【调拨订单】,则提示:“存在下游单据,不能取消签字”,签字失败。

开发
实现 【库存其他入库单】、【采购入库】、【委托加工入库单】交易类型增加“自动内部调拨”参数,可勾选或反选。

1、在“ic_transactiontype.bmf”元数据文件中新增“自动内部调拨”参数 autointrans
2、添加完后升级元数据。
3、在TransTypeExtendVO 类中添加字段

package nc.vo.ic.transtype;

import nc.vo.ic.pub.define.ICPubMetaNameConst;
import nc.vo.pub.IVOMeta;
import nc.vo.pub.SuperVO;
import nc.vo.pub.lang.UFBoolean;
import nc.vo.pub.lang.UFDateTime;
import nc.vo.pubapp.pattern.model.meta.entity.vo.VOMetaFactory;

public class TransTypeExtendVO extends SuperVO {

  // 影响成本
  public static final String BAFFECTCOST = "baffectcost";

  // 影响现存量
  public static final String BAFFECTONHAND = "baffectonhand";

  // 审批后自动推式生成其它出入库单
  public static final String BAPPROVEPUSHBILL = "bapprovepushbill";

  // 保存即审批
  public static final String BAUTOAPPROVE = "bautoapprove";

  // 保存即签字
  public static final String BAUTOSIGN = "bautosign";

  // 核销方式
  public static final String CAVTYPE = "cavtype";

  // 助促销品出库
  public static final String BSALEPROMOTION = "bsalepromotion";

  // 适用零售
  public static final String BRETAIL = "bretail";
  
  //自动内部调拨 add by 2020-09-03
  public static final String AUTOINTRANS = "autointrans";
  
  // 申请出库类型
  public static final String DEST_BILLTYPECODE = "dest_billtypecode";

  // 出入库标识
  public static final String FINOUTFLAG = "finoutflag";

  // 单据类型主键
  // public static final String PK_BILLTYPEID = "pk_billtypeid";

  // 集团
  public static final String PK_GROUP = "pk_group";

  // 库存交易类型主键
  public static final String PK_TRANSTYPE = "pk_transtype";

  // 库存交易类型编码
  public static final String TRANSTYPECODE = "transtypecode";

  // 时间戳
  public static final String TS = "ts";
  
  //寄存消耗结算方
  public static final String FCONSSETTLEFLAG = "fconssettleflag";

  private static final long serialVersionUID = 216342704177031780L;

  public UFBoolean getBaffectcost() {
    return (UFBoolean) this.getAttributeValue(TransTypeExtendVO.BAFFECTCOST);
  }

  public UFBoolean getBaffectonhand() {
    return (UFBoolean) this.getAttributeValue(TransTypeExtendVO.BAFFECTONHAND);
  }

  public UFBoolean getBapprovepushbill() {
    return (UFBoolean) this
        .getAttributeValue(TransTypeExtendVO.BAPPROVEPUSHBILL);
  }

  public UFBoolean getBautoapprove() {
    return (UFBoolean) this.getAttributeValue(TransTypeExtendVO.BAUTOAPPROVE);
  }

  public UFBoolean getBautosign() {
    return (UFBoolean) this.getAttributeValue(TransTypeExtendVO.BAUTOSIGN);
  }

  public Integer getCavtype() {
    return (Integer) this.getAttributeValue(TransTypeExtendVO.CAVTYPE);
  }

  public UFBoolean getBsalepromotion() {
    return (UFBoolean) this.getAttributeValue(TransTypeExtendVO.BSALEPROMOTION);
  }

  public UFBoolean getBretail() {
    return (UFBoolean) this.getAttributeValue(TransTypeExtendVO.BRETAIL);
  }
  
  public UFBoolean getAutointrans() {
	    return (UFBoolean) this.getAttributeValue(TransTypeExtendVO.AUTOINTRANS);
  }

  public String getDest_billtypecode() {
    return (String) this.getAttributeValue(TransTypeExtendVO.DEST_BILLTYPECODE);
  }

  public Integer getFinoutflag() {
    return (Integer) this.getAttributeValue(TransTypeExtendVO.FINOUTFLAG);
  }

  public Integer getFconssettleflag() {
    return (Integer) this.getAttributeValue(TransTypeExtendVO.FCONSSETTLEFLAG);
  }
  
  @Override
  public IVOMeta getMetaData() {
    IVOMeta meta = VOMetaFactory.getInstance().getVOMeta("ic.ic_transtype");
    return meta;
  }

  // public String getPk_billtypeid() {
  // return (String) this.getAttributeValue(TransTypeExtendVO.PK_BILLTYPEID);
  // }

  public String getPk_group() {
    return (String) this.getAttributeValue(TransTypeExtendVO.PK_GROUP);
  }

  public String getPk_transtype() {
    return (String) this.getAttributeValue(TransTypeExtendVO.PK_TRANSTYPE);
  }

  public String getTranstypecode() {
    return (String) this.getAttributeValue(TransTypeExtendVO.TRANSTYPECODE);
  }

  public UFDateTime getTs() {
    return (UFDateTime) this.getAttributeValue(TransTypeExtendVO.TS);
  }

  public void setBaffectcost(UFBoolean baffectcost) {
    this.setAttributeValue(TransTypeExtendVO.BAFFECTCOST, baffectcost);
  }

  public void setBaffectonhand(UFBoolean baffectonhand) {
    this.setAttributeValue(TransTypeExtendVO.BAFFECTONHAND, baffectonhand);
  }

  public void setBapprovepushbill(UFBoolean bapprovepushbill) {
    this.setAttributeValue(TransTypeExtendVO.BAPPROVEPUSHBILL, bapprovepushbill);
  }

  public void setBautoapprove(UFBoolean bautoapprove) {
    this.setAttributeValue(TransTypeExtendVO.BAUTOAPPROVE, bautoapprove);
  }

  public void setBautosign(UFBoolean bautosign) {
    this.setAttributeValue(TransTypeExtendVO.BAUTOSIGN, bautosign);
  }

  public void setCavtype(Integer cavtype) {
    this.setAttributeValue(TransTypeExtendVO.CAVTYPE, cavtype);
  }

  public void setBsalepromotion(UFBoolean bsalepromotion) {
    this.setAttributeValue(TransTypeExtendVO.BSALEPROMOTION, bsalepromotion);
  }

  public void setBretail(UFBoolean bretail) {
    this.setAttributeValue(TransTypeExtendVO.BRETAIL, bretail);
  }
  
  public void setAutointrans(UFBoolean autointrans) {
	  this.setAttributeValue(TransTypeExtendVO.AUTOINTRANS, autointrans);  
  }
  
  public void setDest_billtypecode(String dest_billtypecode) {
    this.setAttributeValue(TransTypeExtendVO.DEST_BILLTYPECODE,
        dest_billtypecode);
  }

  public void setFinoutflag(Integer finoutflag) {
    this.setAttributeValue(TransTypeExtendVO.FINOUTFLAG, finoutflag);
  }

  // public void setPk_billtypeid(String pk_billtypeid) {
  // this.setAttributeValue(TransTypeExtendVO.PK_BILLTYPEID, pk_billtypeid);
  // }

  public void setPk_group(String pk_group) {
    this.setAttributeValue(TransTypeExtendVO.PK_GROUP, pk_group);
  }

  public void setPk_transtype(String pk_transtype) {
    this.setAttributeValue(TransTypeExtendVO.PK_TRANSTYPE, pk_transtype);
  }

  public void setTranstypecode(String transtypecode) {
    this.setAttributeValue(TransTypeExtendVO.TRANSTYPECODE, transtypecode);
  }

  public void setTs(UFDateTime ts) {
    this.setAttributeValue(TransTypeExtendVO.TS, ts);
  }

  public String getCtrantypeid() {
    return (String) this.getAttributeValue(ICPubMetaNameConst.CTRANTYPEID);
  }

  public void setCtrantypeid(String ctrantypeid) {
    this.setAttributeValue(ICPubMetaNameConst.CTRANTYPEID, ctrantypeid);
  }

  public void setFconssettleflag(Integer fconssettleflag) {
    this.setAttributeValue(TransTypeExtendVO.FCONSSETTLEFLAG, fconssettleflag);
  }
  
}

交易类型扩展编辑器类 GeneralTransTypePanelFor45

package nc.ui.ic.transtype;

import nc.ui.pub.bill.BillData;
import nc.ui.pub.transtype.EditorContext;
import nc.vo.ic.transtype.TransTypeExtendVO;
import nc.vo.pub.BusinessException;
import nc.vo.pub.lang.UFBoolean;

/**
 * 
 * <p>
 * <b>本类主要完成以下功能:</b> 采购入库单的交易类型扩展界面 注:45为采购入库单的单据类型
 * <ul>
 * <li>
 * </ul>
 * 
 * <p>
 * <p>
 * 
 * @version 6.5
 * @since 6.5
 * @time 2020-09-03 下午16:24:14
 */
public class GeneralTransTypePanelFor45 extends GeneralTransTypePanel {

	@Override
	public Object getTransTypeExtObj(EditorContext context) throws BusinessException {
		TransTypeExtendVO vo = (TransTypeExtendVO) super.getTransTypeExtObj(context);
	
		// 自动内部调拨 add by  2020-09-03
		if (((Boolean) this.getValue(TransTypeExtendVO.AUTOINTRANS)).booleanValue()) {
			vo.setAutointrans(UFBoolean.TRUE);
		} else {
			vo.setAutointrans(UFBoolean.FALSE);
		}

		return vo;
	}

	@Override
	public void processItemView(BillData billData) {
		super.processItemView(billData);

		// 核销类型
		super.setVisible(billData, TransTypeExtendVO.CAVTYPE, false);
//    super.setWidth(billData, TransTypeExtendVO.CAVTYPE);

		// 保存即签字
		super.setVisible(billData, TransTypeExtendVO.BAUTOSIGN, true);
		
	    // 自动内部调拨 add by 2020-09-03
	    super.setVisible(billData, TransTypeExtendVO.AUTOINTRANS, true);
	    super.setWidth(billData, TransTypeExtendVO.AUTOINTRANS);
	}
}

package nc.ui.ic.transtype;

import nc.ui.pub.bill.BillData;
import nc.ui.pub.transtype.EditorContext;
import nc.vo.ic.transtype.TransTypeExtendVO;
import nc.vo.pub.BusinessException;
import nc.vo.pub.lang.UFBoolean;

/**
 * 其他出库单的交易类型扩展界面
 * 
 * @since 6.31
 * @version 2013-9-3 上午10:11:28
 * @author 
 */
public class GeneralTransTypePanelFor4A extends GeneralTransTypePanel {

  @Override
  public Object getTransTypeExtObj(EditorContext context)
      throws BusinessException {
    TransTypeExtendVO vo =
        (TransTypeExtendVO) super.getTransTypeExtObj(context);
    // 适用零售
    if (((Boolean) this.getValue(TransTypeExtendVO.BRETAIL)).booleanValue()) {
      vo.setBretail(UFBoolean.TRUE);
    }
    else {
      vo.setBretail(UFBoolean.FALSE);
    }
    
    // 自动内部调拨  add by 2020-09-03
    if (((Boolean) this.getValue(TransTypeExtendVO.AUTOINTRANS)).booleanValue()) {
      vo.setAutointrans(UFBoolean.TRUE);
    }
    else {
      vo.setAutointrans(UFBoolean.FALSE);
    }
    
    return vo;
  }

  @Override
  public void processItemView(BillData billData) {
    super.processItemView(billData);

    // 适用零售
    super.setVisible(billData, TransTypeExtendVO.BRETAIL, true);
    super.setWidth(billData, TransTypeExtendVO.BRETAIL);
    
    // 自动内部调拨 add by  2020-09-03 
    super.setVisible(billData, TransTypeExtendVO.AUTOINTRANS, true);
    super.setWidth(billData, TransTypeExtendVO.AUTOINTRANS);
  }
}

package nc.ui.ic.transtype;

import nc.ui.pub.bill.BillData;
import nc.ui.pub.transtype.EditorContext;
import nc.vo.ic.transtype.TransTypeExtendVO;
import nc.vo.pub.BusinessException;
import nc.vo.pub.lang.UFBoolean;

/**
 * 
 * <p>
 * <b>本类主要完成以下功能:</b> 委外加工入库单的交易类型扩展界面 注:47为委外加工入库单的单据类型
 * <ul>
 * <li>
 * </ul>
 * 
 * <p>
 * <p>
 * 
 * @version 6.0
 * @since 6.0
 * @author songhy
 * @time 2010-6-4 下午02:24:14
 */
public class GeneralTransTypePanelFor47 extends GeneralTransTypePanel {

	@Override
	public Object getTransTypeExtObj(EditorContext context) throws BusinessException {
		TransTypeExtendVO vo = (TransTypeExtendVO) super.getTransTypeExtObj(context);
	
		// 自动内部调拨 add by 2020-09-03
		if (((Boolean) this.getValue(TransTypeExtendVO.AUTOINTRANS)).booleanValue()) {
			vo.setAutointrans(UFBoolean.TRUE);
		} else {
			vo.setAutointrans(UFBoolean.FALSE);
		}

		return vo;
	}

	@Override
	public void processItemView(BillData billData) {
		super.processItemView(billData);

		// 保存即签字
		super.setVisible(billData, TransTypeExtendVO.BAUTOSIGN, false);
		
	    // 自动内部调拨 add by 2020-09-03
	    super.setVisible(billData, TransTypeExtendVO.AUTOINTRANS, true);
	    super.setWidth(billData, TransTypeExtendVO.AUTOINTRANS);
	    
		// 核销类型
		super.setVisible(billData, TransTypeExtendVO.CAVTYPE, true);

	}
}

在单据类型管理中新增此类(GeneralTransTypePanelFor45 ),如图
在这里插入图片描述
在这里插入图片描述
如果界面新增、修改保存报错,则只能后台直接修改数据库了或sql语句插入了。
在这里插入图片描述

编写自动调拨的业务逻辑

做后规则有两种套路:
一个是代码写
代码编写需要在入口类中注册

签字入口类

package nc.bs.ic.m47.sign;

import nc.bs.ic.general.sign.ISignBP;
import nc.bs.ic.general.sign.ISignRuleProvider;
import nc.bs.ic.general.sign.SignBPTemplate;
import nc.bs.ic.m47.base.BPPlugInPoint;
import nc.bs.ic.m47.sign.rule.M47AfterSignAuto5XBillVO;
import nc.bs.ic.m47.sign.rule.AfterSignAutoVerifyRule;
import nc.bs.ic.m47.sign.rule.AfterSignForFI;
import nc.bs.ic.m47.sign.rule.AfterSignRuleForFinanceProcess;
import nc.impl.pubapp.pattern.rule.processer.AroundProcesser;
import nc.vo.ic.m47.entity.SubcontInVO;

/**
 * <p> <b>本类主要完成以下功能:</b> <ul> <li>委托加工入库签字 </ul> <p> <p>
 * 
 * @version 6.0
 * @since 6.0
 * @author wanghna
 * @time 2010-10-25 上午09:23:19
 */
public class SignBP implements ISignBP<SubcontInVO>,
    ISignRuleProvider<SubcontInVO> {

  @Override
  public SubcontInVO[] sign(SubcontInVO[] vos) {
    SignBPTemplate<SubcontInVO> signBP =
        new SignBPTemplate<SubcontInVO>(BPPlugInPoint.SignAction, this);
    return signBP.sign(vos);
  }

  @Override
  public void addAfterRule(SubcontInVO[] vos,
      AroundProcesser<SubcontInVO> processor) {
    // 签字生成存货核算的委托加工入库
    processor.addAfterRule(new AfterSignRuleForFinanceProcess());

    // 签字自动核销
    processor.addAfterRule(new AfterSignAutoVerifyRule());
    // 委托加工入库单签字生成采购副本
    processor.addAfterRule(new AfterSignForFI());
    
    //签字后自动生成调拨订单  add by 2020-09-03
    processor.addAfterRule(new M47AfterSignAuto5XBillVO());

  }

  @Override
  public void addBeforeRule(SubcontInVO[] vos,
      AroundProcesser<SubcontInVO> processor) {
    // do nothing
  }

}

自动生成调拨订单业务处理类

package nc.bs.ic.m47.sign.rule;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;

import nc.bs.dao.BaseDAO;
import nc.bs.dao.DAOException;
import nc.bs.framework.common.NCLocator;
import nc.impl.pubapp.pattern.rule.IRule;
import nc.itf.ic.transtype.ITransTypeExtendQueryService;
import nc.itf.to.m5x.ITransOrderForGeneralIn;
import nc.itf.to.m5x.ITransOrderMaintain;
import nc.itf.uap.IUAPQueryBS;
import nc.itf.uap.pf.IPfExchangeService;
import nc.itf.uap.pf.IplatFormEntry;
import nc.itf.uap.pf.busiflow.PfButtonClickContext;
import nc.jdbc.framework.processor.ColumnProcessor;
import nc.pub.occnc.syn.common.UFBoolean;
import nc.pubitf.uapbd.IMaterialBaseClassPubService;
import nc.pubitf.uapbd.IMaterialPubService_C;
import nc.ui.pub.para.SysInitBO_Client;
import nc.util.mmf.busi.consts.BillTypeConst;
import nc.vo.bd.material.MaterialVO;
import nc.vo.bd.material.marbasclass.MarBasClassVO;
import nc.vo.bd.stordoc.StordocVO;
import nc.vo.ic.m47.entity.SubcontInBodyVO;
import nc.vo.ic.m47.entity.SubcontInHeadVO;
import nc.vo.ic.m47.entity.SubcontInVO;

import nc.vo.ic.transtype.TransTypeExtendVO;
import nc.vo.pub.BusinessException;
import nc.vo.pub.billtype.BilltypeVO;
import nc.vo.pub.lang.UFDouble;
import nc.vo.pub.para.SysInitVO;
import nc.vo.pubapp.pattern.exception.ExceptionUtils;
import nc.vo.to.m5x.entity.BillHeaderVO;
import nc.vo.to.m5x.entity.BillItemVO;
import nc.vo.to.m5x.entity.BillVO;

/**
 * 
 * @description 委托加工入库单签字后生成调拨订单
 * @scene 委托加工单签字
 * @param
 * 
 *
 * @since 6.5
 * @version 2020-09-03
 * @author 
 */
public class M47AfterSignAuto5XBillVO implements IRule<SubcontInVO> {

	@Override
	public void process(SubcontInVO[] vos) {
		if ((vos == null) || (vos.length == 0)) {
			return;
		}

		// 2.如果入库实收数量为负,则结束;
		// 2.如果上游【委托加工入库单】交易类型“自动内部调拨”参数为“否”,则结束;
		// 4.如果 【委托加工入库单】表头仓库档案自定义项6“对方库存组织”为空,则结束;"
		ITransTypeExtendQueryService queryService = NCLocator.getInstance().lookup(ITransTypeExtendQueryService.class);
		for (SubcontInVO subcontInVO : vos) {
			SubcontInHeadVO headVO = subcontInVO.getHead();
			SubcontInBodyVO[] bodyVOs = subcontInVO.getBodys();
			String pk_org = headVO.getPk_org();

			// 1、判断来源单据是否是委托订单-61
			if (headVO == null || !"61".equals(bodyVOs[0].getCsourcetype())) {
				continue;
			}
			// 2判断实收数量为负
			if (headVO.getNtotalnum() == null || headVO.getNtotalnum().compareTo(UFDouble.ZERO_DBL) < 0) {
				continue;
			}
			// 3如果【委托加工入库单】交易类型“自动内部调拨”参数为“否”
			TransTypeExtendVO[] transTypeExtendVO = null;
			try {
				transTypeExtendVO = queryService.queryByIds(new String[] { headVO.getCtrantypeid() });
			} catch (BusinessException e) {
				ExceptionUtils.wrappBusinessException("获取委托加工入库单的交易类型出错" + e.getMessage());
			}
			if (transTypeExtendVO == null || transTypeExtendVO[0].getAutointrans() == null
					|| !transTypeExtendVO[0].getAutointrans().booleanValue()) {// 并上自动调拨参数为否
				continue;
			}
			// 4如果本组织的组织级系统参数“入库触发调拨单交易类型”为空,则提示
			SysInitVO initVO = null;
			try {
				initVO = SysInitBO_Client.queryByParaCode(pk_org, "IC207");
			} catch (BusinessException e) {
				ExceptionUtils.wrappBusinessException("获取业务组织参数 IC207失败!" + e.getMessage());
			}
			if (null == initVO || initVO.getValue() == null) {
				continue;
			}
			// 5如果【委托加工入库单】表头仓库档案自定义项6“对方库存组织”为空
			StordocVO stordocVO = this.getStordocVOById(headVO.getCwarehouseid());
			if (stordocVO == null || stordocVO.getDef6() == null) {
				continue;
			}
			// 6如果【委托加工入库单】表头仓库档案自定义项7“对方仓库”为空则提示
			if (stordocVO.getDef7() == null) {
				continue;
			}

			// 调用单据转换规则 委托加工入库单-调拨订单
			IPfExchangeService ipfes = NCLocator.getInstance().lookup(IPfExchangeService.class);
			BillVO[] billVO = null;
			try {
				billVO = (BillVO[]) ipfes.runChangeDataAryNeedClassify(BillTypeConst.SUBCONTIN, BillTypeConst.TRAN,
						new SubcontInVO[] { subcontInVO }, null, PfButtonClickContext.ClassifyByBusiflow);
			} catch (BusinessException e) {
				ExceptionUtils.wrappBusinessException("走单据转换规则【委托加工入库单-调拨订单】失败" + e.getMessage());
			}

			if (billVO == null) {
				ExceptionUtils.wrappBusinessException("走单据转换规则没有生成调拨订单");
			}
			BillVO tobillVO = billVO[0];

			// 调入调出组织,仓库设置,物流明细行过滤
			BillHeaderVO headerVO = tobillVO.getParentVO();
			BillItemVO[] itemVO = tobillVO.getChildrenVO();

			if (itemVO == null || itemVO.length <= 0) {
				ExceptionUtils.wrappBusinessException("走单据转换规则没有生成调拨订单");
			}

			ArrayList<BillItemVO> itemVOList = new ArrayList<BillItemVO>();
			for (BillItemVO bodyVO : itemVO) {
//	    		bodyVO.setVpricerule("1");
				UFBoolean notZero = UFBoolean.TRUE;
				if (bodyVO.getNnum() == null && bodyVO.getNastnum() == null) {
					notZero = UFBoolean.FALSE;
				}
				if (bodyVO.getNnum().compareTo(UFDouble.ZERO_DBL) < 0
						|| bodyVO.getNastnum().compareTo(UFDouble.ZERO_DBL) < 0) {
					notZero = UFBoolean.FALSE;
				}
				if (notZero.booleanValue()) {
					itemVOList.add(bodyVO);
				}
			}
			tobillVO.setChildrenVO(itemVOList.toArray(new BillItemVO[itemVOList.size()]));
			headerVO.SetCtrantypeid(initVO.getValue());
			headerVO.setCinstockorgid(stordocVO.getDef6());
			String pk_org_v = getOrgVidById(stordocVO.getDef6());
			headerVO.setCinstockorgvid(pk_org_v);
			headerVO.setCinfinanceorgid(stordocVO.getDef6());
			headerVO.setCinfinanceorgvid(pk_org_v);
			headerVO.setPk_org(pk_org);
			headerVO.setPk_org_v(headVO.getPk_org_v());
			headerVO.setCoutfinanceorgid(pk_org);
			headerVO.setCoutfinanceorgvid(headVO.getPk_org_v());
			headerVO.setCtoutfinanceorgid(pk_org);
			headerVO.setCtoutfinanceorgvid(headVO.getPk_org_v());
			BilltypeVO billtypevo = getBilltypeVOById(initVO.getValue());
			String vtrantypecode = "5X-Cxx-03";
			if (billtypevo != null) {
				vtrantypecode = billtypevo.getPk_billtypecode();
			}
			headerVO.setVtrantypecode(vtrantypecode);
			String cbiztypeid = "1001E11000000000WHAO";
			String busitype = getBusitypeVOById(vtrantypecode);
			if (busitype != null) {
				cbiztypeid = busitype;
			}
			headerVO.setCbiztypeid(cbiztypeid);
			tobillVO.setParentVO(headerVO);
			// 每busitypeVO行明细物料按系统 “内部结算规则“,形成调拨订单价格(税率、无税单价、含税单价、无税金额、价税合计)。
			ITransOrderForGeneralIn iTransOrderForGeneralIn = NCLocator.getInstance()
					.lookup(ITransOrderForGeneralIn.class);
			BillVO[] returnvos = null;
			try {
				returnvos = iTransOrderForGeneralIn.setDefaultTransOrder(new BillVO[] { tobillVO });
			} catch (BusinessException e2) {
				ExceptionUtils.wrappBusinessException("调拨订单设置默认值失败:" + e2.getMessage());
			}
			tobillVO = returnvos[0];

			// 保存调拨订单
			IplatFormEntry iplatFormEntry = NCLocator.getInstance().lookup(IplatFormEntry.class);
			ITransOrderMaintain iTransOrderMaintain = NCLocator.getInstance().lookup(ITransOrderMaintain.class);
			subcontInVO.getHead().setStatus(2);
			BillVO[] billvo = null;
			try {
				billvo = iTransOrderMaintain.insertTransOrder(new BillVO[] { tobillVO });
			} catch (BusinessException e1) {
				ExceptionUtils.wrappBusinessException("生成调拨订单保存失败:" + e1.getMessage());
			}

			if (billvo != null) {
				tobillVO = billvo[0];
				// 回写委托加工入库单vdef8, 是否已经自动调拨
				try {
					new BaseDAO().executeUpdate(
							"update ic_subcontin_h set vdef8 ='Y' where vbillcode = '" + headVO.getVbillcode() + "'");
				} catch (DAOException e1) {
					ExceptionUtils.wrappBusinessException("回写委托加工入库单失败!" + e1.getMessage());
				}
			}

			// 根据组织参数,是否审批
			SysInitVO init = null;
			try {
				init = SysInitBO_Client.queryByParaCode(pk_org, "IC208");
			} catch (BusinessException e) {
				ExceptionUtils.wrappBusinessException("获取业务组织参数 IC208失败!" + e.getMessage());
			}
			if (initVO != null && init != null && "已审核".equals(init.getValue())) {
				try {
					iplatFormEntry.processAction("APPROVE", vtrantypecode, null, tobillVO, null, null);
				} catch (BusinessException e) {
					ExceptionUtils.wrappBusinessException("生成调拨订单审批失败:" + e.getMessage());
				}
			}
		}

	}

	/**
	 * 根据pk找仓库
	 * 
	 * @param pk
	 * @return
	 */
	private StordocVO getStordocVOById(String pk) {
		StordocVO stordocVO = null;
		try {
			stordocVO = (StordocVO) getIUAPQueryBS().retrieveByPK(StordocVO.class, pk);
		} catch (BusinessException e) {
			ExceptionUtils.wrappBusinessException("根据pk: " + pk + "找仓库失败:" + e.getMessage());
		}
		return stordocVO;
	}

	/**
	 * 根据pk找交易类型
	 * 
	 * @param pk
	 * @return
	 */
	private BilltypeVO getBilltypeVOById(String pk) {
		BilltypeVO BilltypeVO = null;
		try {
			BilltypeVO = (BilltypeVO) getIUAPQueryBS().retrieveByPK(BilltypeVO.class, pk);
		} catch (BusinessException e) {
			ExceptionUtils.wrappBusinessException("根据pk: " + pk + "找交易类型失败:" + e.getMessage());
		}
		return BilltypeVO;
	}

	/**
	 * 根据交易类型code找业务流程
	 * 
	 * @param vtrantypecode
	 * @return
	 */
	private String getBusitypeVOById(String vtrantypecode) {
		String busitype = null;
		String sql = "select pk_busitype from bd_busitype where  primarybilltype= '" + vtrantypecode + "';";
		try {
			busitype = (String) getIUAPQueryBS().executeQuery(sql, new ColumnProcessor());
		} catch (BusinessException e) {
			ExceptionUtils.wrappBusinessException("根据交易类型code: " + vtrantypecode + "找业务流程失败:" + e.getMessage());
		}
		return busitype;
	}

	/**
	 * 根据pk_org找组织版本pk_org_v
	 * 
	 * @param vtrantypecode
	 * @return
	 */

	private String getOrgVidById(String pk_org) {
		String pk_org_v = null;
		String sql = "select  pk_vid from org_orgs where dr = 0 and enablestate = 2 and pk_org = '" + pk_org + "'";
		try {
			pk_org_v = (String) getIUAPQueryBS().executeQuery(sql, new ColumnProcessor());
		} catch (BusinessException e) {
			ExceptionUtils.wrappBusinessException("根据pk_org: " + pk_org + "找组织版本pk_org_v:" + e.getMessage());
		}
		return pk_org_v;
	}

	private IUAPQueryBS getIUAPQueryBS() {
		return NCLocator.getInstance().lookup(IUAPQueryBS.class);
	}

	/**
	 * 查询物料对应的物料分类code Map<物料pk,物料分类code> panfengc
	 * 
	 * @param pks
	 * @return
	 */
	private Map<String, String> queryMaterialBaseClassCode(String[] pks) {
		Map<String, String> map = new HashMap<String, String>();
		if (pks == null || pks.length == 0)
			return map;
		try {
			// 查询物料对应的物料分类主键
			Map<String, MaterialVO> mapMaterial = this.getIMaterialPubService_C().queryMaterialBaseInfoByPks(pks,
					new String[] { MaterialVO.PK_MARBASCLASS });

			Set<Entry<String, MaterialVO>> setMaterial = mapMaterial.entrySet();
			List<String> pk_marbasclass_list = new ArrayList<String>();
			for (Entry<String, MaterialVO> entry : setMaterial) {
				String Pk_marbasclass = entry.getValue().getPk_marbasclass();
				pk_marbasclass_list.add(Pk_marbasclass);
				if (!map.containsKey(entry.getKey())) {
					map.put(entry.getKey(), Pk_marbasclass);
				}

				if (pk_marbasclass_list.size() == 0) {
					ExceptionUtils.wrappBusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes()
							.getStrByID("4001002_0", "04001002-0410")/*
																		 * @res "查询物料基本分类出错"
																		 */);
				}

			}
			// 根据物料分类pk查询物料分类VO
			MarBasClassVO[] basclass = this.queryMaterialBaseClassByPk(pk_marbasclass_list.toArray(new String[0]),
					false);

			// 建立 Map pk,code, 循环mapMaterial,组件新的数组
			Map<String, String> marbasCodehash = new HashMap<String, String>();
			for (MarBasClassVO marbasvo : basclass) {
				if (!marbasCodehash.containsKey(marbasvo.getPk_marbasclass())) {
					marbasCodehash.put(marbasvo.getPk_marbasclass(), marbasvo.getCode());
				}
			}
			// 根据物料分类pk,找对应的物料分类code
			for (String pk : pks) {
				if (map.containsKey(pk)) {
					String Pk_marbasclass = map.get(pk);
					if (marbasCodehash.containsKey(Pk_marbasclass)) {
						String code = marbasCodehash.get(Pk_marbasclass);
						map.put(pk, code);
					} else
						map.put(pk, null);
				}
			}

		} catch (BusinessException e) {
			ExceptionUtils.wrappException(e);
		}
		return map;
	}

	private IMaterialPubService_C getIMaterialPubService_C() {
		return NCLocator.getInstance().lookup(IMaterialPubService_C.class);
	}

	private MarBasClassVO[] queryMaterialBaseClassByPk(String[] pk_marbasclass, boolean isContainParents) {
		MarBasClassVO[] aterialBaseClass = null;
		try {
			aterialBaseClass = NCLocator.getInstance().lookup(IMaterialBaseClassPubService.class)
					.queryMaterialBaseClassByPks(pk_marbasclass, isContainParents);
		} catch (BusinessException e) {
			// 日志异常
			ExceptionUtils.wrappException(e);
		}
		return aterialBaseClass;
	}
}

取消签字入口注册类

package nc.bs.ic.m47.cancelsign;

import nc.bs.ic.general.cancelsign.CancelSignBPTemplate;
import nc.bs.ic.general.cancelsign.ICancelSignBP;
import nc.bs.ic.general.cancelsign.ICancelSignRuleProvider;
import nc.bs.ic.m47.base.BPPlugInPoint;
import nc.bs.ic.m47.cancelsign.rule.AfterCancelSignAutoVerifyRule;
import nc.bs.ic.m47.cancelsign.rule.AfterCancelSignForFI;
import nc.bs.ic.m47.cancelsign.rule.AfterUnsSgnRuleForFinanceProcess;
import nc.bs.ic.m47.cancelsign.rule.BeforeUnSignRuleForVerty;
import nc.bs.ic.m47.cancelsign.rule.M47CheckTo5XCancelSignRule;
import nc.bs.ic.m47.cancelsign.rule.UnSignRuleFor25;
import nc.bs.ic.pub.cancelsign.rule.CancelSignCheckPickedFlag;
import nc.impl.pubapp.pattern.rule.processer.AroundProcesser;
import nc.vo.ic.m47.entity.SubcontInVO;

/**
 * <p> <b>本类主要完成以下功能:</b> <ul> <li>委托加工入库取消签字 </ul>
 * 
 * @version 6.0
 * @since 6.0
 * @author wanghna
 * @time 2010-10-25 上午09:22:11
 */
public class CancelSignBP implements ICancelSignBP<SubcontInVO>,
    ICancelSignRuleProvider<SubcontInVO> {

  @Override
  public SubcontInVO[] cancelSign(SubcontInVO[] vos) {
    CancelSignBPTemplate<SubcontInVO> cancelSignBP =
        new CancelSignBPTemplate<SubcontInVO>(BPPlugInPoint.CancelSignAction,
            this);
    return cancelSignBP.cancelSign(vos);
  }

  @Override
  public void addAfterRule(SubcontInVO[] vos,
      AroundProcesser<SubcontInVO> processor) {
    // 取消签字 删除存货核算的加工入库
    processor.addAfterRule(new AfterUnsSgnRuleForFinanceProcess());
    // 取消自动核销  删除对应的单据
    processor.addAfterRule(new AfterCancelSignAutoVerifyRule());
    // 委托加工入库签字删除采购副本
    processor.addAfterRule(new AfterCancelSignForFI());
  }

  @Override
  public void addBeforeRule(SubcontInVO[] vos,
      AroundProcesser<SubcontInVO> processor) {

    // 已核销单据不能取消签字
    //processor.addBeforeRule(new BeforeUnSignRuleForVerty());
    // 已开票单据不能取消签字
    processor.addBeforeRule(new UnSignRuleFor25());

    // 已拣配不能取消签字
    processor.addBeforeRule(new CancelSignCheckPickedFlag<SubcontInVO>());
    
    //已自动生成调拨订单不能取消签字  add by  2020-09-03
    processor.addBeforeFinalRule(new M47CheckTo5XCancelSignRule());
  }

}

取消签字校验类

package nc.bs.ic.m47.cancelsign.rule;

import nc.bs.ic.pub.base.ICRule;
import nc.vo.ic.m47.entity.SubcontInVO;
import nc.vo.ic.m47.entity.SubcontInHeadVO;
import nc.vo.pub.BusinessException;
import nc.vo.pubapp.pattern.exception.ExceptionUtils;

/**
 * 
 * @description 检查是否可取消签字,取消签字前检查: 下游是否生成
 *              检查是否已经生成下游【调拨订单】,则提示:“存在下游单据,不能取消签字”,签字失败。
 * @scene 委托加工入库单取消签字
 * @param 无
 * 
 * @since v6.5
 * @author 
 * @version 2020-09-03 
 */
public class M47CheckTo5XCancelSignRule extends ICRule<SubcontInVO> {
	/**
	 * 检查执行情况
	 */
	public void checkExec(SubcontInVO[] vos) throws BusinessException {
		SubcontInHeadVO headvo = null;
		for (SubcontInVO vo : vos) {
			headvo = vo.getHead();
			if ("Y".equals(headvo.getVdef8())) {
				ExceptionUtils.wrappBusinessException("已生成下游调拨订单,不能取消签字");
			}
		}
	}

	/**
	 * 父类方法重写
	 */
	@Override
	public void process(SubcontInVO[] vos) {
		try {
			// 检查执行情况
			this.checkExec(vos);
		} catch (Exception e) {
			ExceptionUtils.wrappException(e);
		}
	}
}

另一个是从脚本注入后规则事件
执行以下脚本插入事件类

insert into PUB_PLUGINITEM (DR, INDUSTRYTYPE, IORDER, LOCALTYPE, PK_PLUGINITEM, TS, VCOMPONENTNAME, VDESCRIPTION, VEVENTTYPE, VEXTENDMODULE, VEXTENDPOINTNAME, VEXTENDTYPE, VMODULENAME, VRULECLASS, VTARGETCLASS)
values (0, '~', null, '~', '1001ZZ100000000AOE0P', '2020-09-02 17:00:39', 'm45', '库存采购入库单取消签字校验是否是字段调拨', 'before', 'ic', 'nc.impl.ic.m45.action.CancelSignAction', 'addBefore', 'IC', 'nc.bs.ic.m45.cancelsign.rule.M45CheckTo5XCancelSignRule', null);

insert into PUB_PLUGINITEM (DR, INDUSTRYTYPE, IORDER, LOCALTYPE, PK_PLUGINITEM, TS, VCOMPONENTNAME, VDESCRIPTION, VEVENTTYPE, VEXTENDMODULE, VEXTENDPOINTNAME, VEXTENDTYPE, VMODULENAME, VRULECLASS, VTARGETCLASS)
values (0, '~', null, '~', '1001ZZ100000000AOA40', '2020-08-31 14:09:39', 'm45', '采购入库单签字后自动调拨', 'after', 'ic', 'nc.impl.ic.m45.action.SignAction', 'addAfter', 'IC', 'nc.bs.ic.m45.sign.rule.M45AfterSignAuto5XBillVO', null);

select * from PUB_PLUGINITEM where VRULECLASS like '%nc.bs.ic.m45%' ORDER BY ts desc;

在这里插入图片描述

自动生成调拨订单业务处理类

package nc.bs.ic.m45.sign.rule;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;

import nc.bs.dao.BaseDAO;
import nc.bs.dao.DAOException;
import nc.bs.framework.common.NCLocator;
import nc.impl.pubapp.pattern.rule.IRule;
import nc.itf.ic.transtype.ITransTypeExtendQueryService;
import nc.itf.to.m5x.ITransOrderForGeneralIn;
import nc.itf.to.m5x.ITransOrderMaintain;
import nc.itf.uap.IUAPQueryBS;
import nc.itf.uap.pf.IPfExchangeService;
import nc.itf.uap.pf.IplatFormEntry;
import nc.itf.uap.pf.busiflow.PfButtonClickContext;
import nc.jdbc.framework.processor.ColumnProcessor;
import nc.pub.occnc.syn.common.UFBoolean;
import nc.pubitf.uapbd.IMaterialBaseClassPubService;
import nc.pubitf.uapbd.IMaterialPubService_C;
import nc.ui.pub.para.SysInitBO_Client;
import nc.util.mmf.busi.consts.BillTypeConst;
import nc.vo.bd.material.MaterialVO;
import nc.vo.bd.material.marbasclass.MarBasClassVO;
import nc.vo.bd.stordoc.StordocVO;
import nc.vo.ic.m45.entity.PurchaseInBodyVO;
import nc.vo.ic.m45.entity.PurchaseInHeadVO;
import nc.vo.ic.m45.entity.PurchaseInVO;
import nc.vo.ic.transtype.TransTypeExtendVO;
import nc.vo.pub.BusinessException;
import nc.vo.pub.billtype.BilltypeVO;
import nc.vo.pub.lang.UFDouble;
import nc.vo.pub.para.SysInitVO;
import nc.vo.pubapp.pattern.exception.ExceptionUtils;
import nc.vo.to.m5x.entity.BillHeaderVO;
import nc.vo.to.m5x.entity.BillItemVO;
import nc.vo.to.m5x.entity.BillVO;

/**
 * 
 * @description 采购入库单签字后生成调拨订单
 * 
 *
 * @since 6.5
 * @version 2020-09-03
 * @author 
 */
public class M45AfterSignAuto5XBillVO implements IRule<PurchaseInVO> {

	@Override
	public void process(PurchaseInVO[] vos) {
		if ((vos == null) || (vos.length == 0)) {
			return;
		}

		// 2.如果入库实收数量为负,则结束;
		// 2.如果上游【采购入库单】交易类型“自动内部调拨”参数为“否”,则结束;
		// 4.如果 【采购入库单】表头仓库档案自定义项6“对方库存组织”为空,则结束;"
		ITransTypeExtendQueryService queryService = NCLocator.getInstance().lookup(ITransTypeExtendQueryService.class);
		for (PurchaseInVO purchaseInVO : vos) {
			PurchaseInHeadVO headVO = purchaseInVO.getHead();
			PurchaseInBodyVO[] bodyVOs = purchaseInVO.getBodys();
			String pk_org = headVO.getPk_org();

			// 1、判断来源单据是否是采购订单-21
//			if (headVO == null || !"21".equals(bodyVOs[0].getCsourcetype())) {
//				continue;
//			}
			// 2判断实收数量为负
			if (headVO.getNtotalnum() == null || headVO.getNtotalnum().compareTo(UFDouble.ZERO_DBL) < 0) {
				continue;
			}
			// 3如果【采购入库单】交易类型“自动内部调拨”参数为“否”
			TransTypeExtendVO[] transTypeExtendVO = null;
			try {
				transTypeExtendVO = queryService.queryByIds(new String[] { headVO.getCtrantypeid() });
			} catch (BusinessException e) {
				ExceptionUtils.wrappBusinessException("获取采购入库单的交易类型出错" + e.getMessage());
			}
			if (transTypeExtendVO == null || transTypeExtendVO[0].getAutointrans() == null
					|| !transTypeExtendVO[0].getAutointrans().booleanValue()) {// 并上自动调拨参数为否
				continue;
			}
			// 4如果本组织的组织级系统参数“入库触发调拨单交易类型”为空,则提示
			SysInitVO initVO = null;
			try {
				initVO = SysInitBO_Client.queryByParaCode(pk_org, "IC205");
			} catch (BusinessException e) {
				ExceptionUtils.wrappBusinessException("获取业务组织参数 IC205失败!" + e.getMessage());
			}
			if (null == initVO || initVO.getValue() == null) {
				continue;
			}
			// 5如果【采购入库单】表头仓库档案自定义项6“对方库存组织”为空
			StordocVO stordocVO = this.getStordocVOById(headVO.getCwarehouseid());
			if (stordocVO == null || stordocVO.getDef6() == null) {
				continue;
			}
			// 6如果【采购入库单】表头仓库档案自定义项7“对方仓库”为空则提示
			if (stordocVO.getDef7() == null) {
				continue;
			}

			// 调用单据转换规则 采购入库单-调拨订单
			IPfExchangeService ipfes = NCLocator.getInstance().lookup(IPfExchangeService.class);
			BillVO[] billVO = null;
			try {
				billVO = (BillVO[]) ipfes.runChangeDataAryNeedClassify(BillTypeConst.PURCHASEIN, BillTypeConst.TRAN, new PurchaseInVO[] { purchaseInVO }, null, PfButtonClickContext.ClassifyByBusiflow);
			} catch (BusinessException e) {
				ExceptionUtils.wrappBusinessException("走单据转换规则【采购入库单-调拨订单】失败" + e.getMessage());
			}

			if (billVO == null) {
				ExceptionUtils.wrappBusinessException("走单据转换规则没有生成调拨订单");
			}
			BillVO tobillVO = billVO[0];

			// 调入调出组织,仓库设置,物流明细行过滤
			BillHeaderVO headerVO = tobillVO.getParentVO();
			BillItemVO[] itemVO = tobillVO.getChildrenVO();

			if (itemVO == null || itemVO.length <= 0) {
				ExceptionUtils.wrappBusinessException("走单据转换规则没有生成调拨订单");
			}

			ArrayList<BillItemVO> itemVOList = new ArrayList<BillItemVO>();
			for (BillItemVO bodyVO : itemVO) {
//	    		bodyVO.setVpricerule("1");
				UFBoolean notZero = UFBoolean.TRUE;
				if (bodyVO.getNnum() == null && bodyVO.getNastnum() == null) {
					notZero = UFBoolean.FALSE;
				}
				if (bodyVO.getNnum().compareTo(UFDouble.ZERO_DBL) < 0
						|| bodyVO.getNastnum().compareTo(UFDouble.ZERO_DBL) < 0) {
					notZero = UFBoolean.FALSE;
				}
				if (notZero.booleanValue()) {
					itemVOList.add(bodyVO);
				}
			}
			tobillVO.setChildrenVO(itemVOList.toArray(new BillItemVO[itemVOList.size()]));
			headerVO.SetCtrantypeid(initVO.getValue());
			headerVO.setCinstockorgid(stordocVO.getDef6());
			String pk_org_v = getOrgVidById(stordocVO.getDef6());
			headerVO.setCinstockorgvid(pk_org_v);
			headerVO.setCinfinanceorgid(stordocVO.getDef6());
			headerVO.setCinfinanceorgvid(pk_org_v);
			headerVO.setPk_org(pk_org);
			headerVO.setPk_org_v(headVO.getPk_org_v());
			headerVO.setCoutfinanceorgid(pk_org);
			headerVO.setCoutfinanceorgvid(headVO.getPk_org_v());
			headerVO.setCtoutfinanceorgid(pk_org);
			headerVO.setCtoutfinanceorgvid(headVO.getPk_org_v());
			BilltypeVO billtypevo = getBilltypeVOById(initVO.getValue());
			String vtrantypecode = "5X-Cxx-03";
			if (billtypevo != null) {
				vtrantypecode = billtypevo.getPk_billtypecode();
			}
			headerVO.setVtrantypecode(vtrantypecode);
			String cbiztypeid = "1001E11000000000WHAO";
			String busitype = getBusitypeVOById(vtrantypecode);
			if (busitype != null) {
				cbiztypeid = busitype;
			}
			headerVO.setCbiztypeid(cbiztypeid);
			tobillVO.setParentVO(headerVO);
			// 每busitypeVO行明细物料按系统 “内部结算规则“,形成调拨订单价格(税率、无税单价、含税单价、无税金额、价税合计)。
			ITransOrderForGeneralIn iTransOrderForGeneralIn = NCLocator.getInstance().lookup(ITransOrderForGeneralIn.class);
			BillVO[] returnvos = null;
			try {
				returnvos = iTransOrderForGeneralIn.setDefaultTransOrder(new BillVO[] { tobillVO });
			} catch (BusinessException e2) {
				ExceptionUtils.wrappBusinessException("调拨订单设置默认值失败:" + e2.getMessage());
			}
			tobillVO = returnvos[0];

			// 保存调拨订单
			IplatFormEntry iplatFormEntry = NCLocator.getInstance().lookup(IplatFormEntry.class);
			ITransOrderMaintain iTransOrderMaintain = NCLocator.getInstance().lookup(ITransOrderMaintain.class);
			purchaseInVO.getHead().setStatus(2);
			BillVO[] billvo = null;
			try {
				billvo = iTransOrderMaintain.insertTransOrder(new BillVO[] { tobillVO });
			} catch (BusinessException e1) {
				ExceptionUtils.wrappBusinessException("生成调拨订单保存失败:" + e1.getMessage());
			}

			if (billvo != null) {
				tobillVO = billvo[0];
				// 回写采购入库单vdef8, 是否已经自动调拨
				try {
					new BaseDAO().executeUpdate(
							"update ic_purchasein_h set vdef8 ='Y' where vbillcode = '" + headVO.getVbillcode() + "'");
				} catch (DAOException e1) {
					ExceptionUtils.wrappBusinessException("回写采购入库单失败!" + e1.getMessage());
				}
			}

			// 根据组织参数,是否审批
			SysInitVO init = null;
			try {
				init = SysInitBO_Client.queryByParaCode(pk_org, "IC206");
			} catch (BusinessException e) {
				ExceptionUtils.wrappBusinessException("获取业务组织参数 IC206失败!" + e.getMessage());
			}
			if (initVO != null && init != null && "已审核".equals(init.getValue())) {
				try {
					iplatFormEntry.processAction("APPROVE", vtrantypecode, null, tobillVO, null, null);
				} catch (BusinessException e) {
					ExceptionUtils.wrappBusinessException("生成调拨订单审批失败:" + e.getMessage());
				}
			}
		}

	}

	/**
	 * 根据pk找仓库
	 * 
	 * @param pk
	 * @return
	 */
	private StordocVO getStordocVOById(String pk) {
		StordocVO stordocVO = null;
		try {
			stordocVO = (StordocVO) getIUAPQueryBS().retrieveByPK(StordocVO.class, pk);
		} catch (BusinessException e) {
			ExceptionUtils.wrappBusinessException("根据pk: " + pk + "找仓库失败:" + e.getMessage());
		}
		return stordocVO;
	}

	/**
	 * 根据pk找交易类型
	 * 
	 * @param pk
	 * @return
	 */
	private BilltypeVO getBilltypeVOById(String pk) {
		BilltypeVO BilltypeVO = null;
		try {
			BilltypeVO = (BilltypeVO) getIUAPQueryBS().retrieveByPK(BilltypeVO.class, pk);
		} catch (BusinessException e) {
			ExceptionUtils.wrappBusinessException("根据pk: " + pk + "找交易类型失败:" + e.getMessage());
		}
		return BilltypeVO;
	}

	/**
	 * 根据交易类型code找业务流程
	 * 
	 * @param vtrantypecode
	 * @return
	 */
	private String getBusitypeVOById(String vtrantypecode) {
		String busitype = null;
		String sql = "select pk_busitype from bd_busitype where  primarybilltype= '" + vtrantypecode + "';";
		try {
			busitype = (String) getIUAPQueryBS().executeQuery(sql, new ColumnProcessor());
		} catch (BusinessException e) {
			ExceptionUtils.wrappBusinessException("根据交易类型code: " + vtrantypecode + "找业务流程失败:" + e.getMessage());
		}
		return busitype;
	}

	/**
	 * 根据pk_org找组织版本pk_org_v
	 * 
	 * @param vtrantypecode
	 * @return
	 */

	private String getOrgVidById(String pk_org) {
		String pk_org_v = null;
		String sql = "select  pk_vid from org_orgs where dr = 0 and enablestate = 2 and pk_org = '" + pk_org + "'";
		try {
			pk_org_v = (String) getIUAPQueryBS().executeQuery(sql, new ColumnProcessor());
		} catch (BusinessException e) {
			ExceptionUtils.wrappBusinessException("根据pk_org: " + pk_org + "找组织版本pk_org_v:" + e.getMessage());
		}
		return pk_org_v;
	}

	private IUAPQueryBS getIUAPQueryBS() {
		return NCLocator.getInstance().lookup(IUAPQueryBS.class);
	}

	/**
	 * 查询物料对应的物料分类code Map<物料pk,物料分类code> panfengc
	 * 
	 * @param pks
	 * @return
	 */
	private Map<String, String> queryMaterialBaseClassCode(String[] pks) {
		Map<String, String> map = new HashMap<String, String>();
		if (pks == null || pks.length == 0)
			return map;
		try {
			// 查询物料对应的物料分类主键
			Map<String, MaterialVO> mapMaterial = this.getIMaterialPubService_C().queryMaterialBaseInfoByPks(pks,
					new String[] { MaterialVO.PK_MARBASCLASS });

			Set<Entry<String, MaterialVO>> setMaterial = mapMaterial.entrySet();
			List<String> pk_marbasclass_list = new ArrayList<String>();
			for (Entry<String, MaterialVO> entry : setMaterial) {
				String Pk_marbasclass = entry.getValue().getPk_marbasclass();
				pk_marbasclass_list.add(Pk_marbasclass);
				if (!map.containsKey(entry.getKey())) {
					map.put(entry.getKey(), Pk_marbasclass);
				}

				if (pk_marbasclass_list.size() == 0) {
					ExceptionUtils.wrappBusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes()
							.getStrByID("4001002_0", "04001002-0410")/*
																		 * @res "查询物料基本分类出错"
																		 */);
				}

			}
			// 根据物料分类pk查询物料分类VO
			MarBasClassVO[] basclass = this.queryMaterialBaseClassByPk(pk_marbasclass_list.toArray(new String[0]),
					false);

			// 建立 Map pk,code, 循环mapMaterial,组件新的数组
			Map<String, String> marbasCodehash = new HashMap<String, String>();
			for (MarBasClassVO marbasvo : basclass) {
				if (!marbasCodehash.containsKey(marbasvo.getPk_marbasclass())) {
					marbasCodehash.put(marbasvo.getPk_marbasclass(), marbasvo.getCode());
				}
			}
			// 根据物料分类pk,找对应的物料分类code
			for (String pk : pks) {
				if (map.containsKey(pk)) {
					String Pk_marbasclass = map.get(pk);
					if (marbasCodehash.containsKey(Pk_marbasclass)) {
						String code = marbasCodehash.get(Pk_marbasclass);
						map.put(pk, code);
					} else
						map.put(pk, null);
				}
			}

		} catch (BusinessException e) {
			ExceptionUtils.wrappException(e);
		}
		return map;
	}

	private IMaterialPubService_C getIMaterialPubService_C() {
		return NCLocator.getInstance().lookup(IMaterialPubService_C.class);
	}

	private MarBasClassVO[] queryMaterialBaseClassByPk(String[] pk_marbasclass, boolean isContainParents) {
		MarBasClassVO[] aterialBaseClass = null;
		try {
			aterialBaseClass = NCLocator.getInstance().lookup(IMaterialBaseClassPubService.class)
					.queryMaterialBaseClassByPks(pk_marbasclass, isContainParents);
		} catch (BusinessException e) {
			// 日志异常
			ExceptionUtils.wrappException(e);
		}
		return aterialBaseClass;
	}
}

取消签字校验类

package nc.bs.ic.m45.cancelsign.rule;

import nc.bs.ic.pub.base.ICRule;
import nc.vo.ic.m45.entity.PurchaseInVO;
import nc.vo.ic.m45.entity.PurchaseInHeadVO;
import nc.vo.pub.BusinessException;
import nc.vo.pubapp.pattern.exception.ExceptionUtils;

/**
 * 
 * @description
 * 检查是否可取消签字,取消签字前检查:
 * 下游是否生成
 * 检查是否已经生成下游【调拨订单】,则提示:“存在下游单据,不能取消签字”,签字失败。
 * @scene
 * 采购入库单取消签字
 * @param
 * 无
 * 
 * @since v6.5
 * @author 
 * @version 2020-09-03 下午04:48:10
 */
public class M45CheckTo5XCancelSignRule extends ICRule<PurchaseInVO> {
	 /**
	   * 检查执行情况
	   */
	  public void checkExec(PurchaseInVO[] vos) throws BusinessException {
		  PurchaseInHeadVO headvo = null;
	    for (PurchaseInVO vo : vos) {
	    	headvo = vo.getHead();
	    	if ("Y".equals(headvo.getVdef8())) {
	    		ExceptionUtils.wrappBusinessException("已生成下游调拨订单,不能取消签字");
	    	} 
	    }
	  }

	  /**
	   * 父类方法重写
	   */
	  @Override
	  public void process(PurchaseInVO[] vos) {
	    try {
	      // 检查执行情况
	      this.checkExec(vos);
	    }
	    catch (Exception e) {
	      ExceptionUtils.wrappException(e);
	    }
	  }
}

转库单的逻辑可以根据上面委托加工入库或者采购入库的方式编写

接下来就是单据转换规则的配置
如采购入库单-调拨订单的转换规则配置:
在单据转换规则界面中新增 【采购入库单】转【调拨订单】记录
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
其他单据依次添加配置。

以上就是大概的流程,如有不对的地方,欢迎留言指出,大家共同学习进步。

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值