|
@@ -0,0 +1,110 @@
|
|
|
|
+package nckd.wnq01.wnq.scm.plugin.form;
|
|
|
|
+
|
|
|
|
+import com.alibaba.druid.util.StringUtils;
|
|
|
|
+import kd.bos.bill.AbstractBillPlugIn;
|
|
|
|
+import kd.bos.dataentity.entity.DynamicObject;
|
|
|
|
+import kd.bos.dataentity.entity.DynamicObjectCollection;
|
|
|
|
+import kd.bos.entity.datamodel.events.PropertyChangedArgs;
|
|
|
|
+import kd.bos.form.events.AfterDoOperationEventArgs;
|
|
|
|
+import kd.bos.orm.query.QCP;
|
|
|
|
+import kd.bos.orm.query.QFilter;
|
|
|
|
+import kd.bos.servicehelper.BusinessDataServiceHelper;
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
+import java.util.Calendar;
|
|
|
|
+import java.util.Date;
|
|
|
|
+import java.util.EventObject;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * 表单标识:销售合同(nckd_conm_salcontract_ext)
|
|
|
|
+ * @author wanghaiwu_kd
|
|
|
|
+ * @date 2025/03/15
|
|
|
|
+ */
|
|
|
|
+public class SaleContractCusEditPlugin extends AbstractBillPlugIn {
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void registerListener(EventObject e) {
|
|
|
|
+ super.registerListener(e);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void afterDoOperation(AfterDoOperationEventArgs e) {
|
|
|
|
+ super.afterDoOperation(e);
|
|
|
|
+
|
|
|
|
+ if(StringUtils.equals("nckd_barsplitqty", e.getOperateKey())){
|
|
|
|
+ calculateYearSaleQty();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void propertyChanged(PropertyChangedArgs e) {
|
|
|
|
+ super.propertyChanged(e);
|
|
|
|
+
|
|
|
|
+ String key = e.getProperty().getName();
|
|
|
|
+
|
|
|
|
+ //总销量
|
|
|
|
+ if("nckd_totalqty".equals(key) || "org".equals(key) || "dept".equals(key) || "biztimebegin".equals(key)){
|
|
|
|
+ calculateYearSaleQty();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ *
|
|
|
|
+ */
|
|
|
|
+ private void calculateYearSaleQty(){
|
|
|
|
+ for (int i = 1; i <= 12; i++) {
|
|
|
|
+ String qtyField = "nckd_qty" + i;
|
|
|
|
+
|
|
|
|
+ this.getModel().setValue(qtyField, BigDecimal.ZERO);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ DynamicObject org = (DynamicObject) this.getModel().getValue("org");
|
|
|
|
+ DynamicObject dept = (DynamicObject) this.getModel().getValue("dept");
|
|
|
|
+ Date bizDate = (Date) this.getModel().getValue("biztimebegin");
|
|
|
|
+ BigDecimal totalQty = (BigDecimal) this.getModel().getValue("nckd_totalqty");
|
|
|
|
+
|
|
|
|
+ if(org == null || dept == null || bizDate == null || totalQty.compareTo(BigDecimal.ZERO) <= 0){
|
|
|
|
+// this.getView().showTipNotification("请先检查是否维护了【销售组织、销售部门、起始日期、总销售量】");
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
|
+ calendar.setTime(bizDate);
|
|
|
|
+
|
|
|
|
+ QFilter qFilter = new QFilter("org.id", QCP.equals, org.getPkValue());
|
|
|
|
+ qFilter.and(new QFilter("nckd_saledept.id", QCP.equals, dept.getPkValue()));
|
|
|
|
+ qFilter.and(new QFilter("nckd_year", QCP.equals, calendar.get(Calendar.YEAR)));
|
|
|
|
+
|
|
|
|
+ DynamicObject yearTask = BusinessDataServiceHelper.loadSingle("nckd_yeartask", qFilter.toArray());
|
|
|
|
+
|
|
|
|
+ if(yearTask == null) {
|
|
|
|
+ this.getView().showTipNotification("请先检查是否维护了【年度任务量比例】");
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ DynamicObjectCollection entrys = yearTask.getDynamicObjectCollection("entryentity");
|
|
|
|
+
|
|
|
|
+ int month = calendar.get(Calendar.MONTH) + 1;
|
|
|
|
+ for(DynamicObject entry : entrys){
|
|
|
|
+ if(month == entry.getInt("seq")) {
|
|
|
|
+ BigDecimal sumQty = BigDecimal.ZERO;
|
|
|
|
+
|
|
|
|
+ for (; month <= 12; month++) {
|
|
|
|
+ String qtyField = "nckd_qty" + month;
|
|
|
|
+ String rateField = "nckd_erate" + month;
|
|
|
|
+
|
|
|
|
+ if (entry.getBigDecimal(rateField) == null) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ BigDecimal qty = totalQty.multiply(entry.getBigDecimal(rateField)).divide(new BigDecimal(100), 2, BigDecimal.ROUND_HALF_UP);
|
|
|
|
+ sumQty = sumQty.add(qty);
|
|
|
|
+ if (month == 12) {
|
|
|
|
+ qty = qty.add(totalQty.subtract(sumQty));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ this.getModel().setValue(qtyField, qty);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+}
|