123 lines
5.9 KiB
Java
123 lines
5.9 KiB
Java
|
|
package tqq9.lc123.cloud.app.plugin.form.pm;
|
||
|
|
|
||
|
|
import com.alibaba.fastjson.JSONObject;
|
||
|
|
import com.google.gson.Gson;
|
||
|
|
import kd.bos.bill.AbstractBillPlugIn;
|
||
|
|
import kd.bos.dataentity.entity.DynamicObject;
|
||
|
|
import kd.bos.dataentity.utils.StringUtils;
|
||
|
|
import kd.bos.form.ConfirmCallBackListener;
|
||
|
|
import kd.bos.form.ConfirmTypes;
|
||
|
|
import kd.bos.form.MessageBoxOptions;
|
||
|
|
import kd.bos.form.MessageBoxResult;
|
||
|
|
import kd.bos.form.control.events.ItemClickEvent;
|
||
|
|
import kd.bos.form.events.MessageBoxClosedEvent;
|
||
|
|
import kd.bos.logging.Log;
|
||
|
|
import kd.bos.logging.LogFactory;
|
||
|
|
import kd.bos.orm.query.QCP;
|
||
|
|
import kd.bos.orm.query.QFilter;
|
||
|
|
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
||
|
|
import kd.sdk.plugin.Plugin;
|
||
|
|
import tqq9.lc123.cloud.app.plugin.utils.HttpRequestUtils;
|
||
|
|
|
||
|
|
import java.io.IOException;
|
||
|
|
import java.math.BigDecimal;
|
||
|
|
import java.math.RoundingMode;
|
||
|
|
import java.util.EventObject;
|
||
|
|
import java.util.HashMap;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 单据界面插件
|
||
|
|
*/
|
||
|
|
public class PurOrderCloseBillPlugin extends AbstractBillPlugIn implements Plugin {
|
||
|
|
private final static Log logger = LogFactory.getLog(PurOrderCloseBillPlugin.class);
|
||
|
|
private static String URL;
|
||
|
|
private static String FLXT_TOKEN;
|
||
|
|
|
||
|
|
@Override
|
||
|
|
public void registerListener(EventObject e) {
|
||
|
|
super.registerListener(e);
|
||
|
|
this.addItemClickListeners("tbmain");
|
||
|
|
}
|
||
|
|
static {
|
||
|
|
DynamicObject url = BusinessDataServiceHelper.loadSingle("tqq9_thirdconfig", "name",
|
||
|
|
new QFilter[]{new QFilter("number", QCP.equals, "FLXT_Undeduct_Url")});
|
||
|
|
URL = url != null ? url.getString("name") : null;
|
||
|
|
DynamicObject token = BusinessDataServiceHelper.loadSingle("tqq9_thirdconfig", "name",
|
||
|
|
new QFilter[]{new QFilter("number", QCP.equals, "FLXT_TOKEN")});
|
||
|
|
FLXT_TOKEN = token != null ? token.getString("name") : null;
|
||
|
|
}
|
||
|
|
|
||
|
|
@Override
|
||
|
|
public void itemClick(ItemClickEvent evt) {
|
||
|
|
super.itemClick(evt);
|
||
|
|
String itemKey = evt.getItemKey();
|
||
|
|
DynamicObject dataEntity = this.getModel().getDataEntity();
|
||
|
|
Boolean tqq9_isrebatecalculate = dataEntity.getBoolean("tqq9_isrebatecalculate");//是否使用返利
|
||
|
|
if (StringUtils.equals("close", itemKey)&& tqq9_isrebatecalculate) {
|
||
|
|
ConfirmCallBackListener confirmCallBacks = new ConfirmCallBackListener("isrebate", this);
|
||
|
|
// 设置回调提示
|
||
|
|
String confirmTip = "关闭时是否释放返利金额";
|
||
|
|
this.getView().showConfirm(confirmTip, MessageBoxOptions.OKCancel, ConfirmTypes.Default, confirmCallBacks);
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
@Override
|
||
|
|
public void confirmCallBack(MessageBoxClosedEvent messageBoxClosedEvent) {
|
||
|
|
// 回调标识正确,并且点击了确认
|
||
|
|
if (StringUtils.equals(messageBoxClosedEvent.getCallBackId(), "isrebate") && messageBoxClosedEvent.getResult() == MessageBoxResult.Yes) {
|
||
|
|
DynamicObject dataEntity = this.getModel().getDataEntity();
|
||
|
|
// todo 在此添加业务逻辑
|
||
|
|
BigDecimal tqq9_hshfsyje = dataEntity.getBigDecimal("tqq9_hshfsyje");//含税货返使用金额
|
||
|
|
BigDecimal tqq9_hsxfsyje = dataEntity.getBigDecimal("tqq9_hsxfsyje");//含税现返使用金额
|
||
|
|
String tqq9_hfid = dataEntity.getString("tqq9_hfid");//货返id
|
||
|
|
String tqq9_xfid = dataEntity.getString("tqq9_xfid");//现返id
|
||
|
|
String billno = dataEntity.getString("tqqbillno9_xfid");//单据编号
|
||
|
|
BigDecimal oneHundred = new BigDecimal(100);
|
||
|
|
HashMap<String, String> tokenMap = new HashMap<String, String>();
|
||
|
|
tokenMap.put("Authorization", FLXT_TOKEN);
|
||
|
|
|
||
|
|
if (tqq9_hshfsyje.compareTo(BigDecimal.ZERO) > 0) {
|
||
|
|
BigDecimal notaxamount = tqq9_hshfsyje.multiply(oneHundred.divide(oneHundred.add(new BigDecimal(13)), 10, RoundingMode.HALF_UP)).setScale(2, RoundingMode.HALF_UP);
|
||
|
|
BigDecimal taxamount = tqq9_hshfsyje.subtract(notaxamount);//税额
|
||
|
|
JSONObject bodyMap = new JSONObject();
|
||
|
|
bodyMap.put("id", tqq9_hfid);
|
||
|
|
bodyMap.put("lockMoney", tqq9_hshfsyje);
|
||
|
|
bodyMap.put("lockTaxAmount", taxamount);
|
||
|
|
Gson gson = new Gson();
|
||
|
|
try {
|
||
|
|
String bodyString = HttpRequestUtils.postJson(URL ,bodyMap.toString(), tokenMap);
|
||
|
|
HashMap map = gson.fromJson(bodyString, HashMap.class);
|
||
|
|
Boolean data = (Boolean) map.get("data");
|
||
|
|
if (!data) {
|
||
|
|
this.getView().showErrorNotification("采购订单:" + billno + ",释放返利金额成功");
|
||
|
|
}
|
||
|
|
} catch (IOException ex) {
|
||
|
|
throw new RuntimeException(ex);
|
||
|
|
}
|
||
|
|
//现返审核
|
||
|
|
} else if (tqq9_hsxfsyje.compareTo(BigDecimal.ZERO) > 0) {
|
||
|
|
BigDecimal notaxamount = tqq9_hsxfsyje.multiply(oneHundred.divide(oneHundred.add(new BigDecimal(13)), 10, RoundingMode.HALF_UP)).setScale(2, RoundingMode.HALF_UP);
|
||
|
|
BigDecimal taxamount = tqq9_hsxfsyje.subtract(notaxamount);//税额
|
||
|
|
JSONObject bodyMap = new JSONObject();
|
||
|
|
bodyMap.put("id", tqq9_xfid);
|
||
|
|
bodyMap.put("lockMoney", tqq9_hsxfsyje);
|
||
|
|
bodyMap.put("lockTaxAmount", taxamount);
|
||
|
|
Gson gson = new Gson();
|
||
|
|
try {
|
||
|
|
String bodyString = HttpRequestUtils.postJson(URL, bodyMap.toString(), tokenMap);
|
||
|
|
HashMap map = gson.fromJson(bodyString, HashMap.class);
|
||
|
|
Boolean data = (Boolean) map.get("data");
|
||
|
|
if (!data) {
|
||
|
|
this.getView().showErrorNotification("采购订单:" + billno + ",释放返利金额成功");
|
||
|
|
}
|
||
|
|
} catch (IOException ex) {
|
||
|
|
throw new RuntimeException(ex);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
// this.getView().showSuccessNotification("confirm call back success");
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
}
|
||
|
|
}
|