public override void OnAfterCreateLink(CreateLinkEventArgs e)
{
base.OnAfterCreateLink(e);
ExtendedDataEntity[] bills = e.TargetExtendedDataEntities.FindByEntityKey("FBillHead");
foreach (var item in bills)
{
//收款明细
Entity entityType = e.TargetBusinessInfo.GetEntity("FREFUNDBILLENTRY");
DynamicObjectCollection MxEntityRows = entityType.DynamicProperty.GetValue(item.DataEntity) as DynamicObjectCollection;
//源单明细
Entity SourcesType = e.TargetBusinessInfo.GetEntity("FREFUNDBILLSRCENTRY");
DynamicObjectCollection SourceBillRows = SourcesType.DynamicProperty.GetValue(item.DataEntity) as DynamicObjectCollection;
//获取自定义参数
object OmsAmount = null;
object OmsRemark = null;
Object OmsDate = null;
object OmsBankCode = null;
bool isGet = this.Option.TryGetVariableValue("OmsAmount", out OmsAmount);
bool isGet1 = this.Option.TryGetVariableValue("OmsRemark", out OmsRemark);
this.Option.TryGetVariableValue("OmsDate", out OmsDate);
this.Option.TryGetVariableValue("OmsBankCode", out OmsBankCode);
if (isGet && isGet1 && SourceBillRows.Count > 0 && MxEntityRows.Count > 0)
{
//单据日期
if (OmsDate != null)
{
item.DataEntity["Date"] = OmsDate;
}
//明细行
MxEntityRows[0]["REFUNDAMOUNTFOR"] = OmsAmount; //应退金额
MxEntityRows[0]["REFUNDAMOUNT"] = OmsAmount; //应退金额本位币
MxEntityRows[0]["REALREFUNDAMOUNTFOR"] = OmsAmount; //表体实退金额
MxEntityRows[0]["REALREFUNDAMOUNT"] = OmsAmount; //应退金额本位币
MxEntityRows[0]["REFUNDAMOUNTFOR_E"] = OmsAmount; //退款金额
MxEntityRows[0]["REFUNDAMOUNT_E"] = OmsAmount; //退款金额本位币
MxEntityRows[0]["NOTE"] = OmsRemark; //备注
//我方银行账号
if (OmsBankCode != null)
{
var findResult = Common.CommonHelper.GetDynamicObject(Context, "CN_BANKACNT", string.Format("FNumber='{0}'", OmsBankCode));
if (findResult.isSuccess)
{
MxEntityRows[0]["ACCOUNTID_ID"] = findResult.data[0];
MxEntityRows[0]["ACCOUNTID"] = findResult.data;
}
}
//源单明细
//SourceBillRows[0]["REALREFUNDAMOUNT"] = OmsAmount; //源单明细本次退款金额
//SourceBillRows[0]["REALREFUNDAMOUNTMB"] = OmsAmount; //源单明细退款金额金额本位币
//单据头
item.DataEntity["REFUNDAMOUNTFOR_H"] = OmsAmount; //退款金额
item.DataEntity["REFUNDAMOUNT_H"] = OmsAmount; //退款金额本位币
item.DataEntity["REFUNDTOTALAMOUNTFOR"] = OmsAmount; //应退金额
item.DataEntity["REALREFUNDAMOUNTFOR"] = OmsAmount; //实退金额
item.DataEntity["REFUNDTOTALAMOUNT"] = OmsAmount; //应退金额本位币
item.DataEntity["REALREFUNDAMOUNT"] = OmsAmount; //实退金额本位币
//剩余待处理金额
decimal excessTotalAmount = Convert.ToDecimal(OmsAmount);
foreach (var sourceRow in SourceBillRows)
{
decimal realAmount = Convert.ToDecimal(sourceRow["REALREFUNDAMOUNT"]);
if (realAmount >= excessTotalAmount)
{
sourceRow["REALREFUNDAMOUNT"] = excessTotalAmount;
sourceRow["REALREFUNDAMOUNTMB"] = excessTotalAmount;
break;
}
else
{
excessTotalAmount -= realAmount;
sourceRow["REALREFUNDAMOUNT"] = realAmount;
sourceRow["REALREFUNDAMOUNTMB"] = realAmount;
}
}
}
}
}
推荐阅读