调拨申请和分步式调出单都增加了一个调拨商品单据体。该插件实现了两个单据的调拨商品单据体在单据转换时进行携带。 这个段代码简单的实现了该功能,但还不是很完善。希望可以帮助到有需要的小伙伴
using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel;
using Kingdee.BOS;
using Kingdee.BOS.Resource;
using Kingdee.K3.SCM.Contracts;
using Kingdee.BOS.JSON;
using Kingdee.BOS.Util;
using Kingdee.BOS.App.Data;
using Kingdee.BOS.Core;
using Kingdee.BOS.Core.Metadata.EntityElement;
using Kingdee.BOS.Core.Metadata.FieldElement;
using Kingdee.BOS.Core.Metadata.ConvertElement.PlugIn;
using Kingdee.BOS.Core.Metadata.ConvertElement.PlugIn.Args;
using Kingdee.BOS.Core.Metadata;
using Kingdee.BOS.Orm;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.ServiceHelper;
using Kingdee.BOS.Contracts;
namespace DWG.K3.SCM.App.Stock.ConvertPlug
{
[Description("调拨申请单转换分步式调出单")]
public class TransApplyToTransOut : AbstractConvertPlugIn
{
private const string applyFormId = "STK_TRANSFERAPPLY";//调拨申请单标识
public override void AfterConvert(AfterConvertEventArgs e)
{
base.AfterConvert(e);
//获取明细信息单据体第一行的数据实体
ExtendedDataEntity EntityFirstRow = e.Result.FindByEntityKey("FSTKTRSOUTENTRY").FirstOrDefault<ExtendedDataEntity>();
//获取明细信息单据体第一行的数据包
DynamicObject EntityFirstRowDataEntity = EntityFirstRow.DataEntity;
//获取明细信息单据体第一行源单数据集合
DynamicObjectCollection SrcBIllInfos = (DynamicObjectCollection)EntityFirstRowDataEntity["FSTKTSTKRANSFEROUTENTRY_Link"];
//获取明细信息单据体第一行源单数据集合中的第一个源单信息
DynamicObject SrcBillInfo = SrcBIllInfos[0]; //第一个源单数据,如果多个源单对SrcBIllInfos进行遍历处理多源单数据目(前只支持一行数据只有一个源单)
//获取源单ID
long SrcBillID = Convert.ToInt64(SrcBillInfo["SBillID"]); //获取源单单据内码
//获取源单数据包(调拨申请单数据包)
DynamicObject SourceObject = BusinessDataServiceHelper.LoadSingle(this.Context, SrcBillID, e.SourceBusinessInfo, null);
//获取源单单据体数据(调拨申请调拨商品明细单据体)
DynamicObjectCollection SourceTransMaterialEntryRows = SourceObject["F_STK_TRANSAPPTRANMATERIAL"] as DynamicObjectCollection;
//所有目标单据数据包集合
var headEntity = e.Result.FindByEntityKey("FBillHead");
//遍历目标单据数据包集合
foreach (var extendedDataEntity in headEntity)
{
DynamicObjectCollection entryCollection = null; //调拨申请单调拨商品明细单据体数据包集合
//目标单据的调拨商品明细单据体数据集合
entryCollection = extendedDataEntity.DataEntity["F_STK_TRANSOUTTRANMATERIAL"] as DynamicObjectCollection;
//由于系统会自动创建一行数据,所以需要将该数据清除
entryCollection.Clear();
int i = 0;
foreach (DynamicObject SourceTransMaterialEntryRow in SourceTransMaterialEntryRows)
{
//获得分步式调出单的调拨商品明细行的空数据包
DynamicObject newRowObj = new DynamicObject(e.TargetBusinessInfo.GetEntryEntity("F_STK_TRANSOUTTRANMATERIAL").DynamicObjectType);
//给空的分步式调出单的调拨商品明细行复制
newRowObj["Seq"] = i+1; //行号
newRowObj["FTranMaterialID_Id"] = SourceTransMaterialEntryRow["FTranMaterialID_id"]; //物料代码ID
newRowObj["FTranMaterialID"] = SourceTransMaterialEntryRow["FTranMaterialID"];
newRowObj["FTranUnitID_Id"] = SourceTransMaterialEntryRow["FTRANUNITID_Id"]; //计量单位
newRowObj["FTranUnitID"] = SourceTransMaterialEntryRow["FTRANUNITID"];
newRowObj["FTranQty"] = SourceTransMaterialEntryRow["FTranQty"]; //调出数量
newRowObj["FTranBaseUnitID_Id"] = SourceTransMaterialEntryRow["FTranBaseUnitID_Id"]; //基本计量单位
newRowObj["FTranBaseUnitID"] = SourceTransMaterialEntryRow["FTranBaseUnitID"];
newRowObj["FTranBaseQty"] = SourceTransMaterialEntryRow["FTranBaseQty"]; //基本单位数量
newRowObj["FTranOutStock_Id"] = SourceTransMaterialEntryRow["FTRANOUTSTOCK_Id"]; //调出仓库
newRowObj["FTranOutStock"] = SourceTransMaterialEntryRow["FTRANOUTSTOCK"];
newRowObj["FTranInStock_Id"] = SourceTransMaterialEntryRow["FTranInStock_Id"]; //调入仓库
newRowObj["FTranInStock"] = SourceTransMaterialEntryRow["FTranInStock"];
//向目标单据的调拨商品明细单据体数据集合中添加一行数据
entryCollection.Add(newRowObj);
i++;
}
}
}
}
}