|
@@ -0,0 +1,120 @@
|
|
|
|
+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.dataentity.entity.DynamicObjectCollection;
|
|
|
|
+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.orm.query.QCP;
|
|
|
|
+import kd.bos.orm.query.QFilter;
|
|
|
|
+import kd.bos.servicehelper.BusinessDataServiceHelper;
|
|
|
|
+import kd.bos.servicehelper.operation.SaveServiceHelper;
|
|
|
|
+import kd.sdk.plugin.Plugin;
|
|
|
|
+import kd.sys.ricc.common.util.StringUtils;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * 收款处理审核时反写和撤销销售单中的已收金额
|
|
|
|
+ */
|
|
|
|
+public class RecBillAuditOperationServicePlugIn extends AbstractOperationServicePlugIn implements Plugin {
|
|
|
|
+ @Override
|
|
|
|
+ public void onPreparePropertys(PreparePropertysEventArgs e) {
|
|
|
|
+ super.onPreparePropertys(e);
|
|
|
|
+ e.getFieldKeys().add("entry");
|
|
|
|
+ e.getFieldKeys().add("entry.e_corebilltype");
|
|
|
|
+ e.getFieldKeys().add("entry.e_corebillno");
|
|
|
|
+ e.getFieldKeys().add("entry.e_receivableamt");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void beforeExecuteOperationTransaction(BeforeOperationArgs e) {
|
|
|
|
+ // TODO Auto-generated method stub
|
|
|
|
+ super.beforeExecuteOperationTransaction(e);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void updateSaleOrderInfo(EndOperationTransactionArgs e, DynamicObject[] payBills, Boolean iswriteback) {
|
|
|
|
+ List<DynamicObject> scs = new ArrayList<>();
|
|
|
|
+ List<Object> xsddbillnos = new ArrayList<>();
|
|
|
|
+ Boolean existError = false;
|
|
|
|
+
|
|
|
|
+ for(DynamicObject payBill : payBills) {
|
|
|
|
+ DynamicObjectCollection entrys = payBill.getDynamicObjectCollection("entry");
|
|
|
|
+ for(DynamicObject entry : entrys) {
|
|
|
|
+ String e_corebilltype = entry.getString("e_corebilltype");
|
|
|
|
+ String e_corebillno = entry.getString("e_corebillno");
|
|
|
|
+ if("sm_salorder".equals(e_corebilltype) && StringUtils.isNotBlank(e_corebillno)) {
|
|
|
|
+ xsddbillnos.add(e_corebillno);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(!xsddbillnos.isEmpty()) {
|
|
|
|
+ QFilter qf = new QFilter("billno",QCP.in,xsddbillnos);
|
|
|
|
+ DynamicObject[] xsddarray = BusinessDataServiceHelper.load("sm_salorder", "id,billno,recplanentry.r_itemname,recplanentry.r_recadvanceamount", qf.toArray());
|
|
|
|
+ for(DynamicObject payBill : payBills) {
|
|
|
|
+ DynamicObjectCollection entrys = payBill.getDynamicObjectCollection("entry");
|
|
|
|
+ for(DynamicObject entry : entrys) {
|
|
|
|
+ String e_corebillno = entry.getString("e_corebillno");
|
|
|
|
+ BigDecimal e_receivableamt = entry.getBigDecimal("e_receivableamt");//应收金额
|
|
|
|
+ DynamicObject nckd_payname = entry.getDynamicObject("nckd_payname");//项目名称
|
|
|
|
+ if(StringUtils.isNotBlank(e_corebillno)) {
|
|
|
|
+ DynamicObject srsTemp = null;
|
|
|
|
+ for(DynamicObject xsdd : xsddarray) {
|
|
|
|
+ String xxddbillno = xsdd.getString("billno");
|
|
|
|
+ if(xxddbillno.equals(e_corebillno)) {
|
|
|
|
+ srsTemp = xsdd;
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(srsTemp != null) {
|
|
|
|
+ DynamicObjectCollection recplanentry = srsTemp.getDynamicObjectCollection("recplanentry");
|
|
|
|
+ for(DynamicObject recplan : recplanentry) {
|
|
|
|
+ DynamicObject r_itemname = recplan.getDynamicObject("r_itemname");
|
|
|
|
+ if(nckd_payname != null && r_itemname != null && r_itemname.getPkValue().equals(nckd_payname.getPkValue())) {
|
|
|
|
+ BigDecimal receiptallamount = recplan.getBigDecimal("receiptallamount");//已收金额
|
|
|
|
+ if(iswriteback) {
|
|
|
|
+ BigDecimal receiptallamountNew = receiptallamount.add(e_receivableamt);
|
|
|
|
+ recplan.set("receiptallamount", receiptallamountNew);
|
|
|
|
+ }else {
|
|
|
|
+ BigDecimal receiptallamountNew = receiptallamount.subtract(e_receivableamt);
|
|
|
|
+ recplan.set("receiptallamount", receiptallamountNew);
|
|
|
|
+ }
|
|
|
|
+ scs.add(srsTemp);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ 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);
|
|
|
|
+
|
|
|
|
+ DynamicObject[] payBills = e.getDataEntities();
|
|
|
|
+ String opkey = e.getOperationKey();
|
|
|
|
+ if("audit".equals(opkey)) {
|
|
|
|
+ this.updateSaleOrderInfo(e, payBills, true);
|
|
|
|
+ }else if("unaudit".equals(opkey)){
|
|
|
|
+ this.updateSaleOrderInfo(e, payBills, false);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|