263 lines
14 KiB
Java
263 lines
14 KiB
Java
package tqq9.lc123.cloud.app.plugin.form.pm;
|
|
|
|
import kd.bos.algo.DataSet;
|
|
import kd.bos.bill.AbstractBillPlugIn;
|
|
import kd.bos.bill.BillShowParameter;
|
|
import kd.bos.dataentity.OperateOption;
|
|
import kd.bos.dataentity.entity.DynamicObject;
|
|
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
|
import kd.bos.dataentity.utils.StringUtils;
|
|
import kd.bos.db.DB;
|
|
import kd.bos.db.DBRoute;
|
|
import kd.bos.entity.datamodel.IDataModel;
|
|
import kd.bos.entity.datamodel.events.ChangeData;
|
|
import kd.bos.entity.datamodel.events.PropertyChangedArgs;
|
|
import kd.bos.entity.operate.result.OperationResult;
|
|
import kd.bos.form.CloseCallBack;
|
|
import kd.bos.form.ShowType;
|
|
import kd.bos.form.events.BeforeDoOperationEventArgs;
|
|
import kd.bos.form.events.ClosedCallBackEvent;
|
|
import kd.bos.form.field.BasedataEdit;
|
|
import kd.bos.form.field.events.BeforeF7SelectEvent;
|
|
import kd.bos.form.field.events.BeforeF7SelectListener;
|
|
import kd.bos.form.operate.FormOperate;
|
|
import kd.bos.list.ListShowParameter;
|
|
import kd.bos.logging.Log;
|
|
import kd.bos.logging.LogFactory;
|
|
import kd.bos.orm.ORM;
|
|
import kd.bos.orm.query.QCP;
|
|
import kd.bos.orm.query.QFilter;
|
|
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
|
import kd.bos.servicehelper.operation.OperationServiceHelper;
|
|
import kd.bos.servicehelper.operation.SaveServiceHelper;
|
|
import tqq9.lc123.cloud.app.api.utils.Constants;
|
|
|
|
import java.math.BigDecimal;
|
|
import java.util.EventObject;
|
|
import java.util.HashMap;
|
|
|
|
/**
|
|
* 采购退货界面插件
|
|
*/
|
|
public class PurRefundApplyBillPlugin extends AbstractBillPlugIn implements BeforeF7SelectListener {
|
|
private final static Log logger = LogFactory.getLog(PurorderEntryIntroPaybillPlugin.class);
|
|
|
|
@Override
|
|
public void registerListener(EventObject e) {
|
|
super.registerListener(e);
|
|
this.addItemClickListeners("tbmain");
|
|
BasedataEdit tqq9_ph = this.getControl("tqq9_ph");
|
|
// RefBillEdit tqq9_inwarebill = this.getControl("tqq9_inwarebill");
|
|
tqq9_ph.addBeforeF7SelectListener(this);
|
|
// tqq9_inwarebill.addBeforeF7SelectListener(this);
|
|
// this.addClickListeners("tqq9_ydthno");
|
|
|
|
}
|
|
|
|
@Override
|
|
public void closedCallBack(ClosedCallBackEvent closedCallBackEvent) {
|
|
super.closedCallBack(closedCallBackEvent);
|
|
String actionId = closedCallBackEvent.getActionId();
|
|
Object returnData = closedCallBackEvent.getReturnData();
|
|
if (StringUtils.equals("tqq9_otheroutapply", actionId) && returnData != null) {
|
|
String billno = ((HashMap) returnData).get("billno").toString();
|
|
DynamicObject tqq9_otheroutapply = BusinessDataServiceHelper.loadSingle("tqq9_otheroutapply", new QFilter[]{new QFilter("billno", QCP.equals, billno)});
|
|
this.getModel().setValue("tqq9_yythbillno", tqq9_otheroutapply);
|
|
SaveServiceHelper.save(new DynamicObject[]{this.getModel().getDataEntity(true)});
|
|
this.getView().updateView();
|
|
}
|
|
// else if (StringUtils.equals("pm_purrefundapplybill", actionId) && returnData != null) {
|
|
// int size = ((ListSelectedRowCollection) returnData).size();
|
|
// if(size>1){
|
|
// this.getView().showErrorNotification("只允许选择一行入库单");
|
|
// return;
|
|
// }
|
|
//
|
|
// ListSelectedRow listSelectedRow = ((ListSelectedRowCollection) returnData).get(0);
|
|
// //入库单数据查询
|
|
// DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle(listSelectedRow.toString(), "im_purinbill");
|
|
// String billid = listSelectedRow.getPrimaryKeyValue().toString();//单据id
|
|
// String entryid = listSelectedRow.getEntryPrimaryKeyValue().toString();//分录id
|
|
// DynamicObjectCollection billentry = dynamicObject.getDynamicObjectCollection("billentry");
|
|
// for (DynamicObject object : billentry) {
|
|
// String id = object.getString("id");
|
|
// if (StringUtils.equals(id, entryid)) {
|
|
// String wmsentryid = listSelectedRow.getEntryPrimaryKeyValue().toString();//WMS分录id
|
|
// BigDecimal qty = object.getBigDecimal("qty");//入库数量
|
|
// DynamicObject warehouse = object.getDynamicObject("warehouse");//入库仓库
|
|
// Date producedate = object.getDate("producedate");//生产日期
|
|
// Date expirydate = object.getDate("expirydate");//到期日期
|
|
// String lotnumber = object.getString("lotnumber");//批号
|
|
// String tqq9_registration = object.getString("tqq9_registration");//注册证
|
|
// String tqq9_licenseno = object.getString("tqq9_licenseno");//许可证
|
|
// String mainbillentryid = object.getString("mainbillentryid");
|
|
//
|
|
// //采购退货申请循环找分录
|
|
// DynamicObjectCollection billentry1 = this.getModel().getDataEntity(true).getDynamicObjectCollection("billentry");
|
|
// for (DynamicObject object1 : billentry1) {
|
|
// String mainbillentryid1 = object1.getString("mainbillentryid");
|
|
// if (StringUtils.equals(mainbillentryid, mainbillentryid1)) {
|
|
// int seq = object1.getInt("seq");
|
|
// this.getModel().setValue("tqq9_inwarebillid", billid, seq-1);
|
|
// this.getModel().setValue("tqq9_inwarebillentryid", entryid, seq-1);
|
|
// this.getModel().setValue("tqq9_wmsdetailid", wmsentryid, seq-1);
|
|
// this.getModel().setValue("tqq9_maxqty", qty, seq-1);
|
|
// this.getModel().setValue("tqq9_thck", warehouse, seq-1);
|
|
// this.getModel().setValue("tqq9_productdate", producedate, seq-1);
|
|
// this.getModel().setValue("tqq9_expiredate", expirydate, seq-1);
|
|
// this.getModel().setValue("tqq9_ph", lotnumber, seq-1);
|
|
// this.getModel().setValue("tqq9_registration", tqq9_registration, seq-1);
|
|
// this.getModel().setValue("tqq9_licenseno", tqq9_licenseno, seq-1);
|
|
// this.getView().updateView();
|
|
// }
|
|
//
|
|
// }
|
|
// }
|
|
// }
|
|
//// if (billentry.size() > rowKey) {
|
|
//// DynamicObject dynamicObject1 = billentry.get(rowKey);
|
|
////// String billid = listSelectedRow.getPrimaryKeyValue().toString();//单据id
|
|
////// String entryid = listSelectedRow.getEntryPrimaryKeyValue().toString();//分录id
|
|
//// String wmsentryid = listSelectedRow.getEntryPrimaryKeyValue().toString();//WMS分录id
|
|
//// BigDecimal qty = dynamicObject1.getBigDecimal("qty");//入库数量
|
|
//// DynamicObject warehouse = dynamicObject1.getDynamicObject("warehouse");//入库仓库
|
|
//// Date producedate = dynamicObject1.getDate("producedate");//生产日期
|
|
//// Date expirydate = dynamicObject1.getDate("expirydate");//到期日期
|
|
//// String lotnumber = dynamicObject1.getString("lotnumber");//批号
|
|
//// String tqq9_registration = dynamicObject1.getString("tqq9_registration");//注册证
|
|
//// String tqq9_licenseno = dynamicObject1.getString("tqq9_licenseno");//许可证
|
|
////
|
|
//// }
|
|
//
|
|
// }
|
|
|
|
}
|
|
|
|
/**
|
|
* 异地退货返回事件
|
|
*/
|
|
|
|
|
|
@Override
|
|
public void beforeDoOperation(BeforeDoOperationEventArgs args) {
|
|
super.beforeDoOperation(args);
|
|
FormOperate Operate = (FormOperate) args.getSource();
|
|
Boolean tqq9_isydth = (Boolean) this.getModel().getValue("tqq9_isydth");//是否异地退货
|
|
DynamicObject tqq9_yythbillno = (DynamicObject) this.getModel().getValue("tqq9_yythbillno");//异地退货单号
|
|
String tqq9_ydthno = null;
|
|
if (tqq9_yythbillno != null) {
|
|
tqq9_ydthno = tqq9_yythbillno.getString("billno");
|
|
}
|
|
if (StringUtils.equals("save", Operate.getOperateKey()) && tqq9_isydth && StringUtils.isBlank(tqq9_ydthno)) {
|
|
BillShowParameter param = new BillShowParameter();
|
|
param.setFormId("tqq9_otheroutapply");
|
|
param.setCustomParam("tqq9_otheroutapplybillno", this.getModel().getValue("billno"));//采购退货申请单号
|
|
param.setCloseCallBack(new CloseCallBack(this, "tqq9_otheroutapply"));
|
|
param.getOpenStyle().setShowType(ShowType.Modal);
|
|
this.getView().showForm(param);
|
|
} else if (StringUtils.equals("submit", Operate.getOperateKey()) && tqq9_isydth && StringUtils.isNotBlank(tqq9_ydthno)) {
|
|
DynamicObject tqq9_otheroutapply = BusinessDataServiceHelper.loadSingle("tqq9_otheroutapply", new QFilter[]{new QFilter("billno", QCP.equals, tqq9_ydthno)});
|
|
if (StringUtils.equals(tqq9_otheroutapply.getString("billstatus"), "A")) {
|
|
args.setCancel(true);
|
|
String billno = this.getModel().getValue("billno").toString();
|
|
this.getView().showErrorNotification("采购退货单:" + billno + ",对应的异地退货单号:" + tqq9_ydthno + "未提交");
|
|
}
|
|
} else if (StringUtils.equals("audit", Operate.getOperateKey()) && tqq9_isydth && StringUtils.isNotBlank(tqq9_ydthno)) {
|
|
DynamicObject tqq9_otheroutapply = BusinessDataServiceHelper.loadSingle("tqq9_otheroutapply", new QFilter[]{new QFilter("billno", QCP.equals, tqq9_ydthno)});
|
|
String billstatus = tqq9_otheroutapply.getString("billstatus");
|
|
if (StringUtils.equals("B", billstatus)) {
|
|
OperateOption operateOption = OperateOption.create();
|
|
OperationResult auditResult = OperationServiceHelper.executeOperate(Constants.TYPE_AUDIT, "tqq9_otheroutapply", new DynamicObject[]{tqq9_otheroutapply}, operateOption);
|
|
if (auditResult.isSuccess()) {
|
|
this.getView().showMessage("异地退货审核成功");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* 出库批号根据了做筛选
|
|
*/
|
|
|
|
@Override
|
|
public void beforeF7Select(BeforeF7SelectEvent beforeF7SelectEvent) {
|
|
String name = beforeF7SelectEvent.getProperty().getName();
|
|
if (StringUtils.equals("tqq9_ph", name)) {
|
|
int index = this.getModel().getEntryCurrentRowIndex("billentry");
|
|
DynamicObjectCollection entryentity = this.getModel().getDataEntity(true).getDynamicObjectCollection("billentry");
|
|
DynamicObject dynamicObject = entryentity.get(index);
|
|
DynamicObject material = dynamicObject.getDynamicObject("material");//物料采购信息
|
|
if (material == null) {
|
|
beforeF7SelectEvent.setCancel(true);
|
|
this.getView().showMessage("请先填物料信息");
|
|
} else {
|
|
DynamicObject masterid = material.getDynamicObject("masterid");//物料
|
|
DynamicObject bd_materialinventoryinfo = BusinessDataServiceHelper.loadSingle("bd_materialinventoryinfo", new QFilter[]{new QFilter("masterid", QCP.equals, masterid.getLong("id"))});
|
|
|
|
Boolean enablelot = bd_materialinventoryinfo.getBoolean("enablelot");//是否启用批号管理
|
|
if (enablelot) {
|
|
ListShowParameter param = (ListShowParameter) beforeF7SelectEvent.getFormShowParameter();
|
|
QFilter qF1 = new QFilter("material.number", QCP.equals, masterid.getString("number"));
|
|
param.getListFilterParameter().getQFilters().add(qF1);
|
|
|
|
} else {
|
|
beforeF7SelectEvent.setCancel(true);
|
|
this.getView().showMessage("该物料未启用批号管理");
|
|
}
|
|
}
|
|
}
|
|
// else if (StringUtils.equals("tqq9_inwarebill", name)) {
|
|
// int index = this.getModel().getEntryCurrentRowIndex("billentry");
|
|
// Object mainbillnumber = this.getModel().getValue("mainbillnumber", index);
|
|
// if (mainbillnumber != null) {
|
|
// ListShowParameter param = (ListShowParameter) beforeF7SelectEvent.getFormShowParameter();
|
|
// QFilter qF1 = new QFilter("billentry.mainbillnumber", QCP.equals, mainbillnumber.toString());
|
|
// qF1.and("billstatus", QCP.equals, "C");
|
|
// param.getListFilterParameter().getQFilters().add(qF1);
|
|
// param.setCustomParam("ismergerows", false);
|
|
// CloseCallBack closeCallBack = new CloseCallBack(this.getPluginName(), "pm_purrefundapplybill");
|
|
// param.setCloseCallBack(closeCallBack);
|
|
//
|
|
// }
|
|
// }
|
|
}
|
|
|
|
@Override
|
|
public void propertyChanged(PropertyChangedArgs e) {
|
|
super.propertyChanged(e);
|
|
String name = e.getProperty().getName();
|
|
if (StringUtils.equals("tqq9_ph", name)) {
|
|
ChangeData changeData = e.getChangeSet()[0];
|
|
int rowIndex = changeData.getRowIndex();
|
|
IDataModel model = this.getModel();
|
|
DynamicObject material = (DynamicObject) model.getValue("material", rowIndex);//物料采购信息
|
|
DynamicObject tqq9_ph = (DynamicObject) model.getValue("tqq9_ph", rowIndex);//批号
|
|
if (material != null && tqq9_ph != null) {
|
|
DynamicObject masterid = material.getDynamicObject("masterid");//物料
|
|
if (masterid != null) {
|
|
String id = masterid.getString("id");
|
|
String tqq9_phno = tqq9_ph.getString("number");//批号
|
|
String sql = "/*dialect*/ select sum(fbaseqty) useqty from t_im_inv_realbalance where fmaterialid ='" + id + "' and flotnum ='" + tqq9_phno + "'";
|
|
DataSet pzDataSet = DB.queryDataSet(this.getClass().getName(), DBRoute.of("scm"), sql);
|
|
DataSet copy = pzDataSet.copy();
|
|
DynamicObjectCollection dynamicObjects = ORM.create().toPlainDynamicObjectCollection(copy);
|
|
if (dynamicObjects.size() > 0) {
|
|
BigDecimal useqty = dynamicObjects.get(0).getBigDecimal("useqty");
|
|
model.setValue("tqq9_pckyamount", useqty, rowIndex);
|
|
this.getView().updateView();
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
// else if (StringUtils.equals("tqq9_inwarebill", name)) {
|
|
// IDataModel model = this.getModel();
|
|
//
|
|
// ChangeData changeData = e.getChangeSet()[0];
|
|
// int rowIndex = changeData.getRowIndex();
|
|
// DynamicObject tqq9_inwarebill = (DynamicObject) model.getValue("tqq9_inwarebill", rowIndex);//批号
|
|
//
|
|
// }
|
|
}
|
|
} |