Bläddra i källkod

采购合同提交校验超额&反写和撤销已收金额

wuxiaobing 4 dagar sedan
förälder
incheckning
24ad4ba121

+ 86 - 0
code/wnq/nckd-wnq01-wnq-scm/src/main/java/nckd/poc602/plugin/operate/PurContractSubmitOperationServicePlugIn.java

@@ -0,0 +1,86 @@
+package nckd.poc602.plugin.operate;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.List;
+
+import kd.bos.dataentity.entity.DynamicObject;
+import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
+import kd.bos.entity.plugin.PreparePropertysEventArgs;
+import kd.bos.entity.plugin.args.BeforeOperationArgs;
+import kd.bos.entity.plugin.args.BeginOperationTransactionArgs;
+import kd.bos.entity.plugin.args.EndOperationTransactionArgs;
+import kd.bos.servicehelper.BusinessDataServiceHelper;
+import kd.bos.servicehelper.operation.SaveServiceHelper;
+import kd.sdk.plugin.Plugin;
+
+/**
+ * 采购合同提交校验超额&反写和撤销已收金额
+ */
+public class PurContractSubmitOperationServicePlugIn extends AbstractOperationServicePlugIn implements Plugin {
+    @Override
+    public void onPreparePropertys(PreparePropertysEventArgs e) {
+        super.onPreparePropertys(e);
+        e.getFieldKeys().add("nckd_refbillfield");
+        e.getFieldKeys().add("totalallamount");
+    }
+    
+    @Override
+    public void beforeExecuteOperationTransaction(BeforeOperationArgs e) {
+    	// TODO Auto-generated method stub
+    	super.beforeExecuteOperationTransaction(e);
+    	DynamicObject[] purContracts = e.getDataEntities();
+    	String opkey = e.getOperationKey();
+    	if("submit".equals(opkey)) {
+    		this.updateSaleContractInfo(e, purContracts, true);
+    	}else if("unsubmit".equals(opkey)){
+    		this.updateSaleContractInfo(e, purContracts, false);
+    	}
+    }
+    
+    private void updateSaleContractInfo(BeforeOperationArgs e, DynamicObject[] purContracts, Boolean iswriteback) {
+		List<DynamicObject> scs = new ArrayList<>();
+		Boolean existError = false;
+		for(DynamicObject purContract : purContracts) {
+			DynamicObject saleContract = purContract.getDynamicObject("nckd_refbillfield");
+			BigDecimal purjshj = purContract.getBigDecimal("totalallamount");//价税合计
+			String purbillno = purContract.getString("billno");
+			if(saleContract != null) {
+				DynamicObject saleContractObj = BusinessDataServiceHelper.loadSingle(saleContract.getPkValue(), "id,totalallamount,receiptallamount", null);
+				BigDecimal salejshj = saleContractObj.getBigDecimal("totalallamount");
+				BigDecimal receiptallamount = saleContractObj.getBigDecimal("receiptallamount");
+				if(iswriteback) {
+					BigDecimal receiptallamountNew = purjshj.add(receiptallamount);
+					if(receiptallamountNew.compareTo(salejshj) > 0) {
+						existError = true;
+						String error = "采购合同(" + purbillno + ")的价税合计超额。";
+						e.setCancel(true);
+						e.setCancelMessage(error);
+						break;
+					}else {
+						saleContractObj.set("receiptallamount", receiptallamountNew);
+						scs.add(saleContractObj);
+					}
+				}else {
+					BigDecimal receiptallamountNew = receiptallamount.subtract(purjshj);
+					saleContractObj.set("receiptallamount", receiptallamountNew);
+					scs.add(saleContractObj);
+				}
+			}
+		}
+		if(!existError && !scs.isEmpty()) {
+			SaveServiceHelper.update(scs.toArray(new DynamicObject[0]));
+		}
+    }
+    
+    @Override
+    public void beginOperationTransaction(BeginOperationTransactionArgs e) {
+    	// TODO Auto-generated method stub
+    	super.beginOperationTransaction(e);
+    }
+
+    @Override
+    public void endOperationTransaction(EndOperationTransactionArgs e) {
+        super.endOperationTransaction(e);
+    }
+}