解决:
单据转换插件实现目标单的分录金额字段合计,并赋值到单据头的总金额字段
eq
单据转换插件请参考《金蝶云苍穹_插件开发指南》,文档获取https://dev.kingdee.com/index/docsNew/34f4b44b-0ced-4bbd-8421-251243949f02离线文档获取。
1、效果图
2、插件注册
3、插件代码
package kd.bos.ecos;
import java.math.BigDecimal;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.entity.ExtendedDataEntity;
import kd.bos.entity.botp.plugin.AbstractConvertPlugIn;
import kd.bos.entity.botp.plugin.args.AfterCreateLinkEventArgs;
import kd.bos.entity.botp.plugin.args.InitVariableEventArgs;
public class InitVariableSample extends AbstractConvertPlugIn {
/** 目标单主实体标识 */
private String targetEntityNumber;
@Override
public void initVariable(InitVariableEventArgs e) {
// TODO Auto-generated method stub
super.initVariable(e);
this.targetEntityNumber = this.getTgtMainType().getName();
}
@Override
public void afterCreateLink(AfterCreateLinkEventArgs e) {
// TODO Auto-generated method stub
super.afterCreateLink(e);
ExtendedDataEntity[] billDataEntitys = e.getTargetExtDataEntitySet().FindByEntityKey(this.targetEntityNumber);
// 逐单合计单据头金额字段值
for (ExtendedDataEntity billDataEntity : billDataEntitys) {
this.calcAmount(billDataEntity);
}
}
private void calcAmount(ExtendedDataEntity billDataEntity) {
//目标单单据体数据,采购订单的单据体标识
DynamicObjectCollection entryRows = (DynamicObjectCollection) billDataEntity.getValue("kdec_entryentity");
BigDecimal sumAmount = new BigDecimal(0);
//合计单据体的金额字段
for (DynamicObject dynamicObject : entryRows) {
//分录金额字段标识kdec_amount
BigDecimal amount = dynamicObject.getBigDecimal("kdec_amount");
sumAmount = sumAmount.add(amount);
}
//设置合计字段到单据头的总金额字段(kdec_sumamount)
billDataEntity.setValue("kdec_sumamount", sumAmount);
}
}
【emoji】
推荐阅读