单据转换 汇总下推单据体
金蝶云社区-assassinl10
assassinl10
1人赞赏了该文章 1,994次浏览 未经作者许可,禁止转载编辑于2019年02月13日 16:53:47

[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.K3.Core.MFG.EntityHelper;

namespace YEA.K3.Finance.Business.Plugin.Converts
{
[Description("单据转换插件:报关Packing List下推报关Packing List汇总")]
public class CpBgPackinglistConvertPackinglistHz : AbstractConvertPlugIn
{
//按照英文品名,中文品名,对照表编码(型号)将报关Packing List明细分录内物料的数量填入汇总表体。

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"); //报关Packing List汇总
object[] obs = new object[1];
obs[0] = fid;
var targetBillMeta = MetaDataServiceHelper.Load(this.Context, "YEA_YLBGPackinglist") as FormMetadata;
//报关Packing List
DynamicObject obj =
BusinessDataServiceHelper.Load(this.Context, obs, targetBillMeta.BusinessInfo.GetDynamicObjectType())[0];
DynamicObjectCollection entityCollection = obj["SAL_BGPACKINGLISTENTRY"] 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)
{
DynamicObjectCollection srcCollection = billHead.DataEntity["YEA_Cust_SUMEntry"] as DynamicObjectCollection;
//汇总信息单据体
srcCollection.Clear();

int i = 0;
//英文品名,中文品名,对照表编码(型号)汇总 F_YEA_Qty
foreach (var typeb in (from p in entityCollection
group p by new
{
Ename = Convert.ToString(p["F_YEA_Ename"]),
Cname = Convert.ToString(p["F_YEA_Cname"]),
Model = Convert.ToString(p["F_YEA_model_Id"])
}
into g
select new
{
Ename = g.Key.Ename,
Cname = g.Key.Cname,
Model = g.Key.Model,
Qty = g.Sum(p => Convert.ToDecimal(p["F_YEA_Qty"]))
}))
{
i++;
DynamicObject dyo = new DynamicObject(srcCollection.DynamicCollectionItemPropertyType);
dyo["seq"] = i;
dyo["F_YEA_Enpm"] = typeb.Ename; //英文品名
dyo["F_YEA_Enpm"] = typeb.Ename; //英文品名
dyo["F_YEA_Chpm"] = typeb.Cname; //中文品名
dyo["F_YEA_ModelA_Id"] = typeb.Model; //型号
if (Convert.ToInt64(typeb.Model) != 0)
{
dyo["F_YEA_ModelA"] = BusinessDataServiceHelper.LoadSingle(this.Context,
Convert.ToInt64(typeb.Model),
(businessInfo.GetField("F_YEA_ModelA") as BaseDataField)
.RefFormDynamicObjectType); //型号
}
dyo["F_YEA_QTYSUM"] = typeb.Qty; //QTY

srcCollection.Add(dyo);
}
}

}

}

[/code]