package tqq9.lc123.cloud.app.plugin.form.pm; import com.google.gson.Gson; import kd.bos.bill.AbstractBillPlugIn; import kd.bos.dataentity.entity.DynamicObject; import kd.bos.dataentity.entity.DynamicObjectCollection; import kd.bos.dataentity.utils.StringUtils; import kd.bos.entity.datamodel.IDataModel; import kd.bos.entity.datamodel.events.ChangeData; import kd.bos.entity.datamodel.events.PropertyChangedArgs; import kd.bos.form.IFormView; import kd.bos.orm.query.QCP; import kd.bos.orm.query.QFilter; import kd.bos.servicehelper.BusinessDataServiceHelper; import kd.sdk.plugin.Plugin; import org.springframework.http.ResponseEntity; import tqq9.lc123.cloud.app.api.utils.Constants; import tqq9.lc123.cloud.app.api.utils.HttpClient; import tqq9.lc123.cloud.app.plugin.utils.EntryFieldRefresher; import java.math.BigDecimal; import java.net.ConnectException; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; /** * 单据界面插件 */ public class PurApplyBillPlugin extends AbstractBillPlugIn implements Plugin { private static String URL; static { DynamicObject url = BusinessDataServiceHelper.loadSingle("tqq9_thirdconfig", "name", new QFilter[]{new QFilter("number", QCP.equals, "FLXT_Balance_Url")}); URL = url != null ? url.getString("name") : null; } private final static String ENTRYENTITY = "billentry"; private final static String SH_ORGNUMBER = "SHLC"; private final static String BJ_ORGNUMBER = "BJLC"; private final static String GZ_ORGNUMBER = "GZLC"; @Override public void propertyChanged(PropertyChangedArgs e) { super.propertyChanged(e); String name = e.getProperty().getName(); DynamicObject dataEntity = this.getModel().getDataEntity(true); IDataModel model = this.getModel(); IFormView view = this.getView(); //--------------上海------------------ //集采供应商 if (StringUtils.equals("tqq9_sup_sh", name)) { DynamicObject tqq9_sup_sh = (DynamicObject) model.getValue("tqq9_sup_sh");//供应商 DynamicObject org = BusinessDataServiceHelper.loadSingle("bos_org", new QFilter[]{new QFilter("number", QCP.equals, SH_ORGNUMBER)}); EntryFieldRefresher entryFieldRefresher = new EntryFieldRefresher(); entryFieldRefresher.updateDynamicObjectByOrg(SH_ORGNUMBER, "supplier", tqq9_sup_sh, model); String tqq9_mulcombofield1 = tqq9_sup_sh.getString("tqq9_mulcombofield1"); model.setValue("tqq9_suparea_sh", tqq9_mulcombofield1); HashMap queryMap =new HashMap<>(); queryMap.put("supplierId",tqq9_sup_sh.getString("number")); queryMap.put("companyId",org.getString("number")); Gson gson = new Gson(); try { ResponseEntity responseEntity = HttpClient.sendRequest(URL, null, "Authorization", "Bearer b96dad1eb4f84c41bae651162aeacdd3", queryMap, Constants.GET); String jsonString = responseEntity.getBody().toString(); HashMap map = gson.fromJson(jsonString, HashMap.class); ArrayList> data = (ArrayList) map.get("data"); if(data!=null){ for (Map datum : data) { Map dataMap = datum; String type = dataMap.get("type").toString();//类型 BigDecimal totalMoney = new BigDecimal((Double)dataMap.get("totalMoney"));//剩余总金额 BigDecimal totalMoneyAvailable = new BigDecimal((Double)dataMap.get("totalMoneyAvailable")) ;//可使用金额 if(StringUtils.equals(type,"1.0")){ //货返 model.setValue("tqq9_hshfzje_sh",totalMoney);//含税货返总金额 model.setValue("tqq9_hshfkyje_sh",totalMoneyAvailable);//含税货返可用金额 }else if(StringUtils.equals(type,"0.0")){ //现返 model.setValue("tqq9_hsxfzje_sh",totalMoney);//含税现返总金额 model.setValue("tqq9_hsxfkyje_sh",totalMoneyAvailable);//含税现返可用金额 } } } } catch (ConnectException ex) { throw new RuntimeException(ex); } view.updateView(); } //收货仓库 if (StringUtils.equals("tqq9_rewares_sh", name)) { DynamicObject tqq9_rewares_sh = (DynamicObject) model.getValue("tqq9_rewares_sh"); EntryFieldRefresher entryFieldRefresher = new EntryFieldRefresher(); entryFieldRefresher.updateDynamicObjectByOrg(SH_ORGNUMBER, "warehouse", tqq9_rewares_sh, model); view.updateView(); } //采购数量 if (StringUtils.equals("applyqty", name)) { BigDecimal applyqty = (BigDecimal) model.getValue("applyqty"); EntryFieldRefresher entryFieldRefresher = new EntryFieldRefresher(); entryFieldRefresher.sumEntrByOrg(SH_ORGNUMBER, "applyqty", "tqq9_purqty_sh", model); view.updateView(); } //应付金额 if (StringUtils.equals("tqq9_yfje", name)) { BigDecimal tqq9_yfje = (BigDecimal) model.getValue("tqq9_yfje"); EntryFieldRefresher entryFieldRefresher = new EntryFieldRefresher(); entryFieldRefresher.sumEntrByOrg(SH_ORGNUMBER, "tqq9_yfje", "tqq9_payamount_sh", model); view.updateView(); } //优惠金额_单头 if (StringUtils.equals("tqq9_discountamt_sh", name)) { BigDecimal tqq9_discountamt_sh = (BigDecimal) model.getValue("tqq9_discountamt_sh"); EntryFieldRefresher entryFieldRefresher = new EntryFieldRefresher(); entryFieldRefresher.updateAmountByOrg(SH_ORGNUMBER, "tqq9_disamount", tqq9_discountamt_sh, model); view.updateView(); } //货返_单头 if (StringUtils.equals("tqq9_hshfsyje_sh", name)) { BigDecimal tqq9_hshfsyje_sh = (BigDecimal) model.getValue("tqq9_hshfsyje_sh"); EntryFieldRefresher entryFieldRefresher = new EntryFieldRefresher(); entryFieldRefresher.updateAmountByOrg(SH_ORGNUMBER, "tqq9_hfamount", tqq9_hshfsyje_sh, model); view.updateView(); } //现返_单头 if (StringUtils.equals("tqq9_hsxfsyje_sh", name)) { BigDecimal tqq9_hsxfsyje_sh = (BigDecimal) model.getValue("tqq9_hsxfsyje_sh"); EntryFieldRefresher entryFieldRefresher = new EntryFieldRefresher(); entryFieldRefresher.updateAmountByOrg(SH_ORGNUMBER, "tqq9_xfamount", tqq9_hsxfsyje_sh, model); view.updateView(); } //--------------北京------------------ //集采供应商 if (StringUtils.equals("tqq9_sup_bj", name)) { DynamicObject tqq9_sup_bj = (DynamicObject) model.getValue("tqq9_sup_bj"); DynamicObject org = BusinessDataServiceHelper.loadSingle("bos_org", new QFilter[]{new QFilter("number", QCP.equals, BJ_ORGNUMBER)}); EntryFieldRefresher entryFieldRefresher = new EntryFieldRefresher(); entryFieldRefresher.updateDynamicObjectByOrg(BJ_ORGNUMBER, "supplier", tqq9_sup_bj, model); String tqq9_mulcombofield1 = tqq9_sup_bj.getString("tqq9_mulcombofield1"); model.setValue("tqq9_suparea_bj", tqq9_mulcombofield1); HashMap queryMap =new HashMap<>(); queryMap.put("supplierId",tqq9_sup_bj.getString("number")); queryMap.put("companyId",org.getString("number")); Gson gson = new Gson(); try { ResponseEntity responseEntity = HttpClient.sendRequest(URL, null, "Authorization", "Bearer b96dad1eb4f84c41bae651162aeacdd3", queryMap, Constants.GET); String jsonString = responseEntity.getBody().toString(); HashMap map = gson.fromJson(jsonString, HashMap.class); ArrayList> data = (ArrayList) map.get("data"); if(data!=null){ for (Map datum : data) { Map dataMap = datum; String type = dataMap.get("type").toString();//类型 BigDecimal totalMoney = new BigDecimal((Double)dataMap.get("totalMoney"));//剩余总金额 BigDecimal totalMoneyAvailable = new BigDecimal((Double)dataMap.get("totalMoneyAvailable")) ;//可使用金额 if(StringUtils.equals(type,"1.0")){ //货返 model.setValue("tqq9_hshfzje_bj",totalMoney);//含税货返总金额 model.setValue("tqq9_hshfkyje_bj",totalMoneyAvailable);//含税货返可用金额 }else if(StringUtils.equals(type,"0.0")){ //现返 model.setValue("tqq9_hsxfzje_bj",totalMoney);//含税现返总金额 model.setValue("tqq9_hsxfkyje_bj",totalMoneyAvailable);//含税现返可用金额 } } } } catch (ConnectException ex) { throw new RuntimeException(ex); } view.updateView(); } //收货仓库 if (StringUtils.equals("tqq9_rewares_bj", name)) { DynamicObject tqq9_rewares_bj = (DynamicObject) model.getValue("tqq9_rewares_bj"); EntryFieldRefresher entryFieldRefresher = new EntryFieldRefresher(); entryFieldRefresher.updateDynamicObjectByOrg(BJ_ORGNUMBER, "warehouse", tqq9_rewares_bj, model); view.updateView(); } //采购数量 if (StringUtils.equals("applyqty", name)) { BigDecimal applyqty = (BigDecimal) model.getValue("applyqty"); EntryFieldRefresher entryFieldRefresher = new EntryFieldRefresher(); entryFieldRefresher.sumEntrByOrg(BJ_ORGNUMBER, "applyqty", "tqq9_purqty_bj", model); view.updateView(); } //应付金额 if (StringUtils.equals("tqq9_yfje", name)) { BigDecimal tqq9_yfje = (BigDecimal) model.getValue("tqq9_yfje"); EntryFieldRefresher entryFieldRefresher = new EntryFieldRefresher(); entryFieldRefresher.sumEntrByOrg(BJ_ORGNUMBER, "tqq9_yfje", "tqq9_payamount_bj", model); view.updateView(); } //优惠金额_单头 if (StringUtils.equals("tqq9_discountamt_bj", name)) { BigDecimal tqq9_discountamt_bj = (BigDecimal) model.getValue("tqq9_discountamt_bj"); EntryFieldRefresher entryFieldRefresher = new EntryFieldRefresher(); entryFieldRefresher.updateAmountByOrg(BJ_ORGNUMBER, "tqq9_disamount", tqq9_discountamt_bj, model); view.updateView(); } //货返_单头 if (StringUtils.equals("tqq9_hshfsyje_bj", name)) { BigDecimal tqq9_hshfsyje_bj = (BigDecimal) model.getValue("tqq9_hshfsyje_bj"); EntryFieldRefresher entryFieldRefresher = new EntryFieldRefresher(); entryFieldRefresher.updateAmountByOrg(BJ_ORGNUMBER, "tqq9_hfamount", tqq9_hshfsyje_bj, model); view.updateView(); } //现返_单头 if (StringUtils.equals("tqq9_hsxfsyje_bj", name)) { BigDecimal tqq9_hsxfsyje_bj = (BigDecimal) model.getValue("tqq9_hsxfsyje_bj"); EntryFieldRefresher entryFieldRefresher = new EntryFieldRefresher(); entryFieldRefresher.updateAmountByOrg(BJ_ORGNUMBER, "tqq9_xfamount", tqq9_hsxfsyje_bj, model); view.updateView(); } //--------------广州------------------ //集采供应商 if (StringUtils.equals("tqq9_sup_gz", name)) { DynamicObject tqq9_sup_gz = (DynamicObject) model.getValue("tqq9_sup_gz"); DynamicObject org = BusinessDataServiceHelper.loadSingle("bos_org", new QFilter[]{new QFilter("number", QCP.equals, GZ_ORGNUMBER)}); EntryFieldRefresher entryFieldRefresher = new EntryFieldRefresher(); entryFieldRefresher.updateDynamicObjectByOrg(GZ_ORGNUMBER, "supplier", tqq9_sup_gz, model); String tqq9_mulcombofield1 = tqq9_sup_gz.getString("tqq9_mulcombofield1"); model.setValue("tqq9_suparea_gz", tqq9_mulcombofield1); HashMap queryMap =new HashMap<>(); queryMap.put("supplierId",tqq9_sup_gz.getString("number")); queryMap.put("companyId",org.getString("number")); Gson gson = new Gson(); try { ResponseEntity responseEntity = HttpClient.sendRequest(URL, null, "Authorization", "Bearer b96dad1eb4f84c41bae651162aeacdd3", queryMap, Constants.GET); String jsonString = responseEntity.getBody().toString(); HashMap map = gson.fromJson(jsonString, HashMap.class); ArrayList> data = (ArrayList) map.get("data"); if(data!=null){ for (Map datum : data) { Map dataMap = datum; String type = dataMap.get("type").toString();//类型 BigDecimal totalMoney = new BigDecimal((Double)dataMap.get("totalMoney"));//剩余总金额 BigDecimal totalMoneyAvailable = new BigDecimal((Double)dataMap.get("totalMoneyAvailable")) ;//可使用金额 if(StringUtils.equals(type,"1.0")){ //货返 model.setValue("tqq9_hshfzje_gz",totalMoney);//含税货返总金额 model.setValue("tqq9_hshfkyje_gz",totalMoneyAvailable);//含税货返可用金额 }else if(StringUtils.equals(type,"0.0")){ //现返 model.setValue("tqq9_hsxfzje_gz",totalMoney);//含税现返总金额 model.setValue("tqq9_hsxfkyje_gz",totalMoneyAvailable);//含税现返可用金额 } } } } catch (ConnectException ex) { throw new RuntimeException(ex); } view.updateView(); } //收货仓库 if (StringUtils.equals("tqq9_rewares_gz", name)) { DynamicObject tqq9_rewares_gz = (DynamicObject) model.getValue("tqq9_rewares_gz"); EntryFieldRefresher entryFieldRefresher = new EntryFieldRefresher(); entryFieldRefresher.updateDynamicObjectByOrg(GZ_ORGNUMBER, "warehouse", tqq9_rewares_gz, model); view.updateView(); } //采购数量 if (StringUtils.equals("applyqty", name)) { BigDecimal applyqty = (BigDecimal) model.getValue("applyqty"); EntryFieldRefresher entryFieldRefresher = new EntryFieldRefresher(); entryFieldRefresher.sumEntrByOrg(GZ_ORGNUMBER, "applyqty", "tqq9_purqty_gz", model); view.updateView(); } //应付金额 if (StringUtils.equals("tqq9_yfje", name)) { BigDecimal tqq9_yfje = (BigDecimal) model.getValue("tqq9_yfje"); EntryFieldRefresher entryFieldRefresher = new EntryFieldRefresher(); entryFieldRefresher.sumEntrByOrg(GZ_ORGNUMBER, "tqq9_yfje", "tqq9_payamount_gz", model); view.updateView(); } //优惠金额_单头 if (StringUtils.equals("tqq9_discountamt_gz", name)) { BigDecimal tqq9_discountamt_gz = (BigDecimal) model.getValue("tqq9_discountamt_gz"); EntryFieldRefresher entryFieldRefresher = new EntryFieldRefresher(); entryFieldRefresher.updateAmountByOrg(GZ_ORGNUMBER, "tqq9_disamount", tqq9_discountamt_gz, model); view.updateView(); } //货返_单头 if (StringUtils.equals("tqq9_hshfsyje_gz", name)) { BigDecimal tqq9_hshfsyje_gz = (BigDecimal) model.getValue("tqq9_hshfsyje_gz"); EntryFieldRefresher entryFieldRefresher = new EntryFieldRefresher(); entryFieldRefresher.updateAmountByOrg(GZ_ORGNUMBER, "tqq9_hfamount", tqq9_hshfsyje_gz, model); view.updateView(); } //现返_单头 if (StringUtils.equals("tqq9_hsxfsyje_gz", name)) { BigDecimal tqq9_hsxfsyje_gz = (BigDecimal) model.getValue("tqq9_hsxfsyje_gz"); EntryFieldRefresher entryFieldRefresher = new EntryFieldRefresher(); entryFieldRefresher.updateAmountByOrg(GZ_ORGNUMBER, "tqq9_xfamount", tqq9_hsxfsyje_gz, model); view.updateView(); } //分录优惠金额,现返,货返金额分摊 if (StringUtils.equals("tqq9_amount", name)) { EntryFieldRefresher entryFieldRefresher = new EntryFieldRefresher(); BigDecimal tqq9_discountamt_sh = (BigDecimal) model.getValue("tqq9_discountamt_sh"); entryFieldRefresher.updateAmountByOrg(SH_ORGNUMBER, "tqq9_disamount", tqq9_discountamt_sh, model); BigDecimal tqq9_hshfsyje_sh = (BigDecimal) model.getValue("tqq9_hshfsyje_sh"); entryFieldRefresher.updateAmountByOrg(SH_ORGNUMBER, "tqq9_hfamount", tqq9_hshfsyje_sh, model); BigDecimal tqq9_hsxfsyje_sh = (BigDecimal) model.getValue("tqq9_hsxfsyje_sh"); entryFieldRefresher.updateAmountByOrg(SH_ORGNUMBER, "tqq9_xfamount", tqq9_hsxfsyje_sh, model); BigDecimal tqq9_discountamt_bj = (BigDecimal) model.getValue("tqq9_discountamt_bj"); entryFieldRefresher.updateAmountByOrg(BJ_ORGNUMBER, "tqq9_disamount", tqq9_discountamt_bj, model); BigDecimal tqq9_hshfsyje_bj = (BigDecimal) model.getValue("tqq9_hshfsyje_bj"); entryFieldRefresher.updateAmountByOrg(BJ_ORGNUMBER, "tqq9_hfamount", tqq9_hshfsyje_bj, model); BigDecimal tqq9_hsxfsyje_bj = (BigDecimal) model.getValue("tqq9_hsxfsyje_bj"); entryFieldRefresher.updateAmountByOrg(BJ_ORGNUMBER, "tqq9_xfamount", tqq9_hsxfsyje_bj, model); BigDecimal tqq9_discountamt_gz = (BigDecimal) model.getValue("tqq9_discountamt_gz"); entryFieldRefresher.updateAmountByOrg(GZ_ORGNUMBER, "tqq9_disamount", tqq9_discountamt_gz, model); BigDecimal tqq9_hshfsyje_gz = (BigDecimal) model.getValue("tqq9_hshfsyje_gz"); entryFieldRefresher.updateAmountByOrg(GZ_ORGNUMBER, "tqq9_hfamount", tqq9_hshfsyje_gz, model); BigDecimal tqq9_hsxfsyje_gz = (BigDecimal) model.getValue("tqq9_hsxfsyje_gz"); entryFieldRefresher.updateAmountByOrg(GZ_ORGNUMBER, "tqq9_xfamount", tqq9_hsxfsyje_gz, model); } //物料带出最高限价 if (StringUtils.equals("material", name)) { ChangeData changeData = e.getChangeSet()[0]; int rowIndex = changeData.getRowIndex(); DynamicObjectCollection dynamicObjectCollection = dataEntity.getDynamicObjectCollection(ENTRYENTITY); DynamicObject dynamicObject = dynamicObjectCollection.get(rowIndex); DynamicObject material = dynamicObject.getDynamicObject("material"); DynamicObject masterid = material.getDynamicObject("masterid"); DynamicObject bd_material = BusinessDataServiceHelper.loadSingle(masterid.getLong("id"), "bd_material"); DynamicObject org = (DynamicObject)this.getModel().getValue("entryrecorg", rowIndex); //上海 if (StringUtils.equals(SH_ORGNUMBER, org.getString("number"))) { BigDecimal tqq9_maxprice_sh = bd_material.getBigDecimal("tqq9_maxprice_sh"); if (tqq9_maxprice_sh.compareTo(BigDecimal.ZERO) > 0) { getModel().setValue("priceandtax", tqq9_maxprice_sh, rowIndex); getModel().setValue("tqq9_zgcgxj", tqq9_maxprice_sh, rowIndex); } //北京 } else if (StringUtils.equals(BJ_ORGNUMBER, org.getString("number"))) { BigDecimal tqq9_maxprice_bj = bd_material.getBigDecimal("tqq9_maxprice_bj"); if (tqq9_maxprice_bj.compareTo(BigDecimal.ZERO) > 0) { getModel().setValue("priceandtax", tqq9_maxprice_bj, rowIndex); getModel().setValue("tqq9_zgcgxj", tqq9_maxprice_bj, rowIndex); } //广州 } else if (StringUtils.equals(GZ_ORGNUMBER, org.getString("number"))) { BigDecimal tqq9_maxprice_gz = bd_material.getBigDecimal("tqq9_maxprice_gz"); if (tqq9_maxprice_gz.compareTo(BigDecimal.ZERO) > 0) { getModel().setValue("priceandtax", tqq9_maxprice_gz, rowIndex); getModel().setValue("tqq9_zgcgxj", tqq9_maxprice_gz, rowIndex); } } } //校验含税单价和最高限价 if (StringUtils.equals("priceandtax", name)) { ChangeData changeData = e.getChangeSet()[0]; int rowIndex = changeData.getRowIndex(); int seq = rowIndex; BigDecimal newValue = (BigDecimal) changeData.getNewValue(); BigDecimal tqq9_zgcgxj = (BigDecimal) getModel().getValue("tqq9_zgcgxj",seq); if (newValue.compareTo(tqq9_zgcgxj) > 0 && tqq9_zgcgxj.compareTo(BigDecimal.ZERO) > 0) { getModel().setValue("priceandtax", 0,seq); this.getView().showErrorNotification("物料明细分录行" + seq + "含税单价超过最高采购限价,请修改"); } } } }