|  | @@ -0,0 +1,62 @@
 | 
	
		
			
				|  |  | +package nckd.poc602.plugin.operate;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +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.AfterConvertEventArgs;
 | 
	
		
			
				|  |  | +import kd.bos.servicehelper.BusinessDataServiceHelper;
 | 
	
		
			
				|  |  | +import kd.sdk.plugin.Plugin;
 | 
	
		
			
				|  |  | +import org.jetbrains.annotations.NotNull;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +import java.math.BigDecimal;
 | 
	
		
			
				|  |  | +import java.util.HashMap;
 | 
	
		
			
				|  |  | +import java.util.List;
 | 
	
		
			
				|  |  | +import java.util.Map;
 | 
	
		
			
				|  |  | +import java.util.Set;
 | 
	
		
			
				|  |  | +import java.util.stream.Collectors;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +/**
 | 
	
		
			
				|  |  | + * 采购订单转付款申请插件,根据比例计算分摊金额
 | 
	
		
			
				|  |  | + */
 | 
	
		
			
				|  |  | +public class PurBillToPayApplyConvertPlugin extends AbstractConvertPlugIn implements Plugin {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public void afterConvert(AfterConvertEventArgs e) {
 | 
	
		
			
				|  |  | +        super.afterConvert(e);
 | 
	
		
			
				|  |  | +        String targetEntityNumber = this.getTgtMainType().getName();
 | 
	
		
			
				|  |  | +        String srcEntityNumber = this.getSrcMainType().getName();
 | 
	
		
			
				|  |  | +        ExtendedDataEntity[] billDataEntitys = e.getTargetExtDataEntitySet().FindByEntityKey(targetEntityNumber);
 | 
	
		
			
				|  |  | +        for(ExtendedDataEntity billDataEntity : billDataEntitys) {
 | 
	
		
			
				|  |  | +            DynamicObject targetBill = billDataEntity.getDataEntity();
 | 
	
		
			
				|  |  | +            DynamicObjectCollection entryEntity = targetBill.getDynamicObjectCollection("entry");
 | 
	
		
			
				|  |  | +            List<Long> eCorebillid = entryEntity.stream().map(x -> x.getLong("e_corebillid")).collect(Collectors.toList());
 | 
	
		
			
				|  |  | +            if (!eCorebillid.isEmpty()){
 | 
	
		
			
				|  |  | +                //计算物料占比
 | 
	
		
			
				|  |  | +                DynamicObject pmPurorderbill = BusinessDataServiceHelper.loadSingleFromCache(eCorebillid.get(0), "pm_purorderbill");
 | 
	
		
			
				|  |  | +                DynamicObjectCollection billentry = pmPurorderbill.getDynamicObjectCollection("billentry");
 | 
	
		
			
				|  |  | +                BigDecimal amountandtaxSum = billentry.stream().map(x -> x.getBigDecimal("amountandtax")).reduce(BigDecimal.ZERO, BigDecimal::add);
 | 
	
		
			
				|  |  | +                Map<Long,BigDecimal> map=new HashMap();
 | 
	
		
			
				|  |  | +                for (DynamicObject dynamicObject : billentry) {
 | 
	
		
			
				|  |  | +                    DynamicObject material = dynamicObject.getDynamicObject("material");
 | 
	
		
			
				|  |  | +                    BigDecimal amountandtax = dynamicObject.getBigDecimal("amountandtax");
 | 
	
		
			
				|  |  | +                    map.put(material.getLong("id"),amountandtax.divide(amountandtaxSum,6,BigDecimal.ROUND_HALF_UP));
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                //取出付款申请的总金额
 | 
	
		
			
				|  |  | +                BigDecimal ePayamountSum = entryEntity.stream().map(x -> x.getBigDecimal("e_payamount")).reduce(BigDecimal.ZERO, BigDecimal::add);
 | 
	
		
			
				|  |  | +                //填充到标的明细
 | 
	
		
			
				|  |  | +                DynamicObjectCollection nckd_entryentity = targetBill.getDynamicObjectCollection("nckd_entryentity");
 | 
	
		
			
				|  |  | +                for (DynamicObject dynamicObject : nckd_entryentity) {
 | 
	
		
			
				|  |  | +                    DynamicObject nckdMaterial = dynamicObject.getDynamicObject("nckd_material");
 | 
	
		
			
				|  |  | +                    BigDecimal bl = map.get(nckdMaterial.getLong("id"));
 | 
	
		
			
				|  |  | +                    dynamicObject.set("nckd_payrate",bl);
 | 
	
		
			
				|  |  | +                    dynamicObject.set("nckd_payamount",ePayamountSum.multiply(bl));
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +}
 |