单据转换--子单据体下推单据体
金蝶云社区-assassinl10
assassinl10
7人赞赏了该文章 4,968次浏览 未经作者许可,禁止转载编辑于2019年06月05日 15:47:29

[password]123456[/password]

[code]using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Kingdee.BOS.Core;
using Kingdee.BOS.Core.Metadata;
using Kingdee.BOS.Core.Metadata.ConvertElement.PlugIn;
using Kingdee.BOS.Core.Metadata.ConvertElement.PlugIn.Args;
using Kingdee.BOS.Core.Metadata.FieldElement;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.ServiceHelper;
using Kingdee.BOS.Util;

namespace YEA.K3.MFG.ENG.Business.PlugIn.Order
{
[Description("单据转换插件:组装单下推简单生产入库单")]
public class CombinedConvertInStockConvertPlugin : AbstractConvertPlugIn
{
private object fid;

public override void OnGetSourceData(GetSourceDataEventArgs e)
{
DynamicObject sobj = e.SourceData[0];
fid = sobj["FID"];
}

public override void OnAfterFieldMapping(AfterFieldMappingEventArgs e)
{
base.OnAfterFieldMapping(e);
ExtendedDataEntity[] billHead = e.TargetExtendDataEntitySet.FindByEntityKey("FBillHead"); //简单生产入库单
object[] obs = new object[1];
obs[0] = fid;
var targetBillMeta = MetaDataServiceHelper.Load(this.Context, "YEA_Combined") as FormMetadata;
DynamicObject obj =
BusinessDataServiceHelper.Load(this.Context, obs, targetBillMeta.BusinessInfo.GetDynamicObjectType())[0];
DynamicObjectCollection entityCollection = obj["ProductEntity"] as DynamicObjectCollection; //组装单

for (int k = 0; k < billHead.Count(); k++)
{
SetData(billHead[k], entityCollection, e.TargetBusinessInfo);
}
}

private void SetData(ExtendedDataEntity billHead, DynamicObjectCollection entityCollection,
BusinessInfo businessInfo)
{
string stocker = Convert.ToString(billHead["StockerId_ID"]);//仓管员分组

DynamicObjectCollection srcCollection = billHead.DataEntity["Entity"] as DynamicObjectCollection;
srcCollection.Clear();

for (int i = 0; i < entityCollection.Count(); i++)
{
DynamicObjectCollection collection =
entityCollection[i]["STK_ASSEMBLYSUBITEM"] as DynamicObjectCollection; //子单据体

if (!collection.IsNullOrEmptyOrWhiteSpace())
{
int k = 1;
foreach (var data in collection)
{

if (stocker.EqualsIgnoreCase(Convert.ToString(data["FStocker_ID"])))
{

DynamicObject dyo = new DynamicObject(srcCollection.DynamicCollectionItemPropertyType);

#region 赋值

dyo["Seq"] = k; //序号
string bomid = Convert.ToString(data["BomIDSETY_ID"]);
if (!bomid.EqualsIgnoreCase("0"))
{
dyo["BomId_ID"] = bomid; //明细.BOM版本
dyo["BomId"] = BusinessDataServiceHelper.LoadSingle(this.Context, bomid,
(businessInfo.GetField("FBomId") as BaseDataField).RefFormDynamicObjectType);
}
string keeperId = Convert.ToString(data["FKeeperIDSETY_ID"]);
if (!keeperId.EqualsIgnoreCase("0"))
{
dyo["KeeperId_ID"] = keeperId; //明细.保管者
dyo["KeeperId"] = BusinessDataServiceHelper.LoadSingle(this.Context, keeperId,
(businessInfo.GetField("FKeeperId") as BaseDataField).RefFormDynamicObjectType);
}
dyo["KeeperTypeId"] = data["FKeeperTypeIDSETY"]; //明细.保管者类型
dyo["Memo"] = data["DescriptionSETY"]; //明细.备注
string stock = Convert.ToString(data["FStockIDSETY_ID"]);
if (!stock.EqualsIgnoreCase("0"))
{
dyo["StockId_ID"] = stock; //明细.仓库
dyo["StockId"] = BusinessDataServiceHelper.LoadSingle(this.Context, stock,
(businessInfo.GetField("FStockId") as BaseDataField).RefFormDynamicObjectType);
}

string workShop = Convert.ToString(billHead["F_YEA_WorkShopId_ID"]);
if (!workShop.EqualsIgnoreCase("0"))
{
dyo["WorkShopId_ID"] = workShop; //明细.车间=基本信息.生产车间
dyo["WorkShopId"] = BusinessDataServiceHelper.LoadSingle(this.Context, workShop,
(businessInfo.GetField("FWorkShopId1") as BaseDataField).RefFormDynamicObjectType);
}

dyo["Price"] = data["PriceSETY"]; //明细.成本价
string unitId = Convert.ToString(data["FUnitIDSETY_ID"]);
if (!unitId.EqualsIgnoreCase("0"))
{
dyo["FUnitID_ID"] = unitId; //明细.单位
dyo["FUnitID"] = BusinessDataServiceHelper.LoadSingle(this.Context, unitId,
(businessInfo.GetField("FUnitId") as BaseDataField).RefFormDynamicObjectType);
}
string extUnitId = Convert.ToString(data["ExtAuxUnitIdSETY_ID"]);
if (!extUnitId.EqualsIgnoreCase("0"))
{
dyo["ExtAuxUnitId_ID"] = extUnitId; //明细.辅单位
dyo["ExtAuxUnitId"] = BusinessDataServiceHelper.LoadSingle(this.Context, extUnitId,
(businessInfo.GetField("FExtAuxUnitId") as BaseDataField).RefFormDynamicObjectType);
}
string auxPropid = Convert.ToString(data["AuxPropertyIDSETY_ID"]);
if (!auxPropid.EqualsIgnoreCase("0"))
{
dyo["AuxPropId_ID"] = auxPropid; //明细.辅助属性
dyo["AuxPropId"] = BusinessDataServiceHelper.LoadSingle(this.Context, auxPropid,
(businessInfo.GetField("FAuxPropId") as RelatedFlexGroupField)
.RefFormDynamicObjectType);
}
string owner = Convert.ToString(data["FOwnerIDSETY_ID"]);
if (!owner.EqualsIgnoreCase("0"))
{
dyo["OwnerId_ID"] = owner; //明细.货主
dyo["OwnerId"] = BusinessDataServiceHelper.LoadSingle(this.Context, owner,
(businessInfo.GetField("FOwnerId") as BaseDataField)
.RefFormDynamicObjectType);
}
dyo["OwnerTypeId"] = data["OwnerTypeIDSETY"]; //明细.货主类型

string baseUnitId = Convert.ToString(data["FBaseUnitIDSETY_ID"]);
if (!baseUnitId.EqualsIgnoreCase("0"))
{
dyo["BaseUnitId_ID"] = baseUnitId; //明细.基本单位
dyo["BaseUnitId"] = BusinessDataServiceHelper.LoadSingle(this.Context, baseUnitId,
(businessInfo.GetField("FBaseUnitId") as BaseDataField).RefFormDynamicObjectType);
}
dyo["MTONO"] = data["MTONOSETY"]; //明细.计划跟踪号

string lot = Convert.ToString(data["LotSETY_ID"]);
if (!lot.EqualsIgnoreCase("0"))
{
dyo["Lot_ID"] = lot; //明细.批号
dyo["Lot"] = BusinessDataServiceHelper.LoadSingle(this.Context, lot,
(businessInfo.GetField("FLot") as BaseDataField).RefFormDynamicObjectType);
}
dyo["ProduceDate"] = data["FProduceDateSETY"]; //明细.生产日期

string material = Convert.ToString(data["MaterialIDSETY_ID"]);
if (!material.EqualsIgnoreCase("0"))
{
dyo["MaterialId_ID"] = material; //明细.物料编码
dyo["MaterialId"] = BusinessDataServiceHelper.LoadSingle(this.Context, material,
(businessInfo.GetField("FMaterialId") as BaseDataField).RefFormDynamicObjectType);

//明细.库存单位 =子件表.物料编码.库存单位
DynamicObjectCollection stockCollection
=
(data["MaterialIDSETY"] as DynamicObject)["MaterialStock"] as
DynamicObjectCollection;
if (!stockCollection.IsNullOrEmptyOrWhiteSpace())
{
string stockId = Convert.ToString(stockCollection[0]["StoreUnitID_ID"]);
if (!stockId.EqualsIgnoreCase("0"))
{
dyo["stockId_ID"] = stockId; //明细.批号
dyo["StockUnitId"] = BusinessDataServiceHelper.LoadSingle(this.Context, stockId,
(businessInfo.GetField("FStockUnitId") as BaseDataField)
.RefFormDynamicObjectType);
}
}
}

dyo["ExpiryDate"] = data["FEXPIRYDATESETY"]; //明细.有效期至
//dyo["SrcEntrySeq"] = data["Seq"]; //明细.源单分录行号
//dyo["SrcInterId"] = fid; //明细.源单内码
//dyo["SrcEnteryId"] = data["ID"]; //明细.源单内码
dyo["Amount"] = data["AmountSETY"]; //明细.总成本

string stockLocId = Convert.ToString(data["StockPlaceIDSETY_ID"]);
if (!stockLocId.EqualsIgnoreCase("0"))
{
dyo["StockLocId_ID"] = stockLocId; //明细.仓位
dyo["StockLocId"] = BusinessDataServiceHelper.LoadSingle(this.Context, stockLocId,
(businessInfo.GetField("FStockLocId") as BaseDataField).RefFormDynamicObjectType);
}

string secUnitId = Convert.ToString(data["SecUnitIDSETY_ID"]);
if (!secUnitId.EqualsIgnoreCase("0"))
{
dyo["SecUnitId_ID"] = secUnitId; //明细.库存辅单位
dyo["SecUnitId"] = BusinessDataServiceHelper.LoadSingle(this.Context, secUnitId,
(businessInfo.GetField("FSecUnitId") as BaseDataField).RefFormDynamicObjectType);
}
string stockStatus = Convert.ToString(data["FStockStatusIDSETY_ID"]);
if (!stockStatus.EqualsIgnoreCase("0"))
{
dyo["StockStatusId_ID"] = stockStatus; //明细.库存状态
dyo["StockStatusId"] = BusinessDataServiceHelper.LoadSingle(this.Context, stockStatus,
(businessInfo.GetField("FStockStatusId") as BaseDataField).RefFormDynamicObjectType);
}

dyo["StockRealQty"] = Convert.ToDecimal(data["BaseQtySETY"]) - Convert.ToDecimal(data["F_YEA_LLScanBaseQty"]);//明细.库存单位实收数量 =基本单位数量-已扫描数量(成品基本单位)
dyo["RealQty"] = Convert.ToDecimal(data["FQtySETY"]) - Convert.ToDecimal(data["F_YEA_LLScanBaseQty"]);//明细.实收数量=数量-已扫描数量(成品基本单位)
dyo["MustQty"] = Convert.ToDecimal(data["FQtySETY"]) - Convert.ToDecimal(data["F_YEA_LLScanQty"]);//明细.应收数量 =数量-已扫描数量(成品)
dyo["BaseRealQty"] = Convert.ToDecimal(data["BaseQtySETY"]) - Convert.ToDecimal(data["F_YEA_LLScanBaseQty"]);// 明细.基本单位实发数量=基本单位数量-已扫描数量(成品基本单位)
dyo["BaseMustQty"] = Convert.ToDecimal(data["BaseQtySETY"]) - Convert.ToDecimal(data["F_YEA_LLScanBaseQty"]);//明细.基本单位应发数量=基本单位数量-已扫描数量(成品基本单位)

#endregion

k ++;
srcCollection.Add(dyo);
}
}
}
}
}
}
}
[/code]