2025-09-09 08:38:22 +00:00
|
|
|
|
package tqq9.lc123.cloud.app.plugin.form.im;
|
|
|
|
|
|
|
2025-12-11 10:08:15 +00:00
|
|
|
|
import com.alibaba.nacos.common.utils.StringUtils;
|
2025-12-15 05:45:13 +00:00
|
|
|
|
import kd.bos.algo.DataSet;
|
2025-09-09 08:38:22 +00:00
|
|
|
|
import kd.bos.bill.AbstractBillPlugIn;
|
|
|
|
|
|
import kd.bos.dataentity.entity.DynamicObject;
|
|
|
|
|
|
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
2025-12-15 05:45:13 +00:00
|
|
|
|
import kd.bos.db.DB;
|
|
|
|
|
|
import kd.bos.db.DBRoute;
|
2025-09-09 08:38:22 +00:00
|
|
|
|
import kd.bos.entity.datamodel.IDataModel;
|
|
|
|
|
|
import kd.bos.entity.datamodel.events.ChangeData;
|
|
|
|
|
|
import kd.bos.entity.datamodel.events.PropertyChangedArgs;
|
|
|
|
|
|
import kd.bos.form.field.BasedataEdit;
|
2025-12-11 10:08:15 +00:00
|
|
|
|
import kd.bos.form.field.events.BeforeF7SelectEvent;
|
|
|
|
|
|
import kd.bos.form.field.events.BeforeF7SelectListener;
|
|
|
|
|
|
import kd.bos.list.ListShowParameter;
|
2025-12-15 05:45:13 +00:00
|
|
|
|
import kd.bos.orm.ORM;
|
2025-09-09 08:38:22 +00:00
|
|
|
|
import kd.bos.orm.query.QCP;
|
|
|
|
|
|
import kd.bos.orm.query.QFilter;
|
|
|
|
|
|
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
|
|
|
|
|
|
2025-09-13 09:42:55 +00:00
|
|
|
|
import java.math.BigDecimal;
|
2025-12-11 04:34:41 +00:00
|
|
|
|
import java.util.Date;
|
2025-09-09 08:38:22 +00:00
|
|
|
|
import java.util.EventObject;
|
2025-12-11 10:08:15 +00:00
|
|
|
|
import java.util.HashSet;
|
2025-09-09 08:38:22 +00:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 其他出库申请界面插件
|
|
|
|
|
|
*/
|
2025-12-11 10:08:15 +00:00
|
|
|
|
public class OtherOutApplyBillPlugin extends AbstractBillPlugIn implements BeforeF7SelectListener {
|
2025-09-09 08:38:22 +00:00
|
|
|
|
@Override
|
|
|
|
|
|
public void registerListener(EventObject e) {
|
|
|
|
|
|
super.registerListener(e);
|
|
|
|
|
|
this.addItemClickListeners("tbmain");
|
2025-12-11 10:08:15 +00:00
|
|
|
|
BasedataEdit tqq9_materiel = this.getView().getControl("tqq9_materiel");
|
|
|
|
|
|
tqq9_materiel.addBeforeF7SelectListener(this);
|
2025-09-09 08:38:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-11 10:08:15 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* 物料根据所选仓库,组织,是否有库存筛选
|
|
|
|
|
|
*/
|
2025-11-24 03:46:18 +00:00
|
|
|
|
|
2025-12-11 10:08:15 +00:00
|
|
|
|
@Override
|
|
|
|
|
|
public void beforeF7Select(BeforeF7SelectEvent beforeF7SelectEvent) {
|
|
|
|
|
|
String name = beforeF7SelectEvent.getProperty().getName();
|
|
|
|
|
|
if (StringUtils.equals("tqq9_materiel", name)) {
|
|
|
|
|
|
IDataModel model = this.getModel();
|
|
|
|
|
|
int index = model.getEntryCurrentRowIndex("entryentity");
|
|
|
|
|
|
DynamicObjectCollection entryentity = model.getDataEntity(true).getDynamicObjectCollection("entryentity");
|
|
|
|
|
|
DynamicObject dynamicObject = entryentity.get(index);
|
|
|
|
|
|
DynamicObject tqq9_dcck = dynamicObject.getDynamicObject("tqq9_dcck");
|
|
|
|
|
|
if (tqq9_dcck != null) {
|
|
|
|
|
|
DynamicObject dataEntity = model.getDataEntity();
|
|
|
|
|
|
DynamicObject org = dataEntity.getDynamicObject("org");
|
|
|
|
|
|
QFilter qFilter = new QFilter("org.number", QCP.equals, org.getString("number"));
|
|
|
|
|
|
qFilter.and("warehouse.number", QCP.equals, tqq9_dcck.getString("number"));
|
|
|
|
|
|
qFilter.and("qty", QCP.not_equals2, 0);
|
|
|
|
|
|
DynamicObject[] t_im_inv_realbalances = BusinessDataServiceHelper.load("im_inv_realbalance", "id,warehouse,org,material", qFilter.toArray());
|
|
|
|
|
|
HashSet<Long> ids = new HashSet<>();
|
|
|
|
|
|
for (DynamicObject t_im_inv_realbalance : t_im_inv_realbalances) {
|
|
|
|
|
|
DynamicObject material = t_im_inv_realbalance.getDynamicObject("material");
|
|
|
|
|
|
if (material != null) {
|
|
|
|
|
|
ids.add(material.getLong("id"));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
ListShowParameter param = (ListShowParameter) beforeF7SelectEvent.getFormShowParameter();
|
|
|
|
|
|
QFilter qF1 = new QFilter("masterid", QCP.in, ids);
|
|
|
|
|
|
param.getListFilterParameter().getQFilters().add(qF1);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2025-09-19 08:50:17 +00:00
|
|
|
|
|
2025-10-21 10:06:26 +00:00
|
|
|
|
|
2025-09-19 08:50:17 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* 售后单号带出售后信息
|
2025-09-09 08:38:22 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void propertyChanged(PropertyChangedArgs e) {
|
|
|
|
|
|
super.propertyChanged(e);
|
|
|
|
|
|
String name = e.getProperty().getName();
|
|
|
|
|
|
IDataModel model = this.getModel();
|
|
|
|
|
|
if (StringUtils.equals("tqq9_returnapply", name)) {
|
|
|
|
|
|
ChangeData[] changeSet = e.getChangeSet();
|
|
|
|
|
|
DynamicObject newValue = (DynamicObject) changeSet[0].getNewValue();//销售退货申请单
|
|
|
|
|
|
DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle("sm_returnapply", new QFilter[]{new QFilter("billno", QCP.equals, newValue.getString("billno"))});
|
|
|
|
|
|
DynamicObjectCollection billentry = dynamicObject.getDynamicObjectCollection("billentry");
|
|
|
|
|
|
if (billentry.size() > 0) {
|
|
|
|
|
|
DynamicObject entry = billentry.get(0);
|
|
|
|
|
|
String mainbillnumber = entry.getString("mainbillnumber");//核心单据编号
|
|
|
|
|
|
String tqq9_kddh = dynamicObject.getString("tqq9_kddh");//快递单号
|
|
|
|
|
|
DynamicObject tqq9_sskf = dynamicObject.getDynamicObject("tqq9_sskf");//所属客服
|
2025-09-19 08:50:17 +00:00
|
|
|
|
DynamicObject operator = dynamicObject.getDynamicObject("operator");//所属销售
|
2025-09-09 08:38:22 +00:00
|
|
|
|
DynamicObject customer = dynamicObject.getDynamicObject("customer");//订货客户
|
2025-09-19 08:50:17 +00:00
|
|
|
|
DynamicObject sm_salorder = BusinessDataServiceHelper.loadSingle("sm_salorder", new QFilter[]{new QFilter("billno", QCP.equals, mainbillnumber)});
|
|
|
|
|
|
model.setValue("tqq9_saleorderbill", sm_salorder);//对应销售订单号
|
2025-09-09 08:38:22 +00:00
|
|
|
|
model.setValue("tqq9_dpdh", tqq9_kddh);//DP单号
|
|
|
|
|
|
model.setValue("tqq9_sskf", tqq9_sskf);//所属客服
|
|
|
|
|
|
model.setValue("tqq9_ssxs", operator);//所属销售
|
|
|
|
|
|
model.setValue("tqq9_kufptt", customer);//客户发票抬头
|
|
|
|
|
|
}
|
2025-09-13 09:42:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
//物料带出最近价格
|
|
|
|
|
|
if (StringUtils.equals("tqq9_materiel", name)) {
|
|
|
|
|
|
ChangeData[] changeSet = e.getChangeSet();
|
|
|
|
|
|
DynamicObject newValue = (DynamicObject) changeSet[0].getNewValue();//物料库存信息
|
2025-12-11 04:34:41 +00:00
|
|
|
|
if (newValue != null) {
|
2025-10-30 02:52:24 +00:00
|
|
|
|
DynamicObject masterid = newValue.getDynamicObject("masterid");//物料
|
2025-12-11 04:34:41 +00:00
|
|
|
|
if (masterid != null) {
|
2025-10-30 02:52:24 +00:00
|
|
|
|
QFilter purinbillF = new QFilter("billentry.material.id", QCP.equals, newValue.getLong("id"));
|
|
|
|
|
|
purinbillF = purinbillF.and("billstatus", QCP.equals, "C");
|
|
|
|
|
|
//price
|
|
|
|
|
|
DynamicObject[] purinbills = BusinessDataServiceHelper.load("im_purinbill", "id,billno,billentry.material,billentry.price", purinbillF.toArray(), "auditdate desc");
|
2025-12-11 04:34:41 +00:00
|
|
|
|
if (purinbills != null && purinbills.length > 0) {
|
2025-10-30 02:52:24 +00:00
|
|
|
|
DynamicObject purinbill = purinbills[0];
|
|
|
|
|
|
DynamicObjectCollection billentry = purinbill.getDynamicObjectCollection("billentry");
|
|
|
|
|
|
for (DynamicObject dynamicObject : billentry) {
|
|
|
|
|
|
String number = dynamicObject.getString("material.masterid.number");
|
|
|
|
|
|
if (StringUtils.equals(number, masterid.getString("number"))) {
|
|
|
|
|
|
BigDecimal price = dynamicObject.getBigDecimal("price");
|
|
|
|
|
|
this.getModel().setValue("tqq9_price", price);
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
2025-09-13 09:42:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-09-09 08:38:22 +00:00
|
|
|
|
}
|
2025-12-15 05:45:13 +00:00
|
|
|
|
//批号带出生产厂商
|
|
|
|
|
|
if (StringUtils.equals("tqq9_lotnumber", name)||StringUtils.equals("tqq9_dcck", name)||StringUtils.equals("tqq9_materiel", name)) {
|
2025-12-11 04:34:41 +00:00
|
|
|
|
ChangeData[] changeSet = e.getChangeSet();
|
|
|
|
|
|
int rowIndex = changeSet[0].getRowIndex();
|
2025-12-15 05:45:13 +00:00
|
|
|
|
Object tqq9_materiel = model.getValue("tqq9_materiel");
|
|
|
|
|
|
DynamicObject materiel = (tqq9_materiel != null) ? (DynamicObject) tqq9_materiel : null;//物料
|
|
|
|
|
|
Object tqq9_dcck = model.getValue("tqq9_dcck");
|
|
|
|
|
|
DynamicObject dcck = (tqq9_dcck != null) ? (DynamicObject) tqq9_dcck : null;//仓库
|
|
|
|
|
|
Object tqq9_lotnumber = model.getValue("tqq9_lotnumber");
|
|
|
|
|
|
String lotNumber = (tqq9_lotnumber != null) ? (String) tqq9_lotnumber : null;//批号
|
|
|
|
|
|
//物料仓库均不为空
|
|
|
|
|
|
if (materiel != null && dcck != null && StringUtils.isNotBlank(lotNumber)) {
|
|
|
|
|
|
QFilter materielF = new QFilter("material", QCP.equals, materiel.getDynamicObject("masterid").getLong("id"));
|
|
|
|
|
|
QFilter warehouseF = new QFilter("warehouse", QCP.equals, dcck.getLong("id"));
|
|
|
|
|
|
QFilter lotNumberF= new QFilter("lotnum", QCP.equals, lotNumber);
|
2025-12-11 04:34:41 +00:00
|
|
|
|
DynamicObject[] objects = BusinessDataServiceHelper.load("im_inv_realbalance",
|
|
|
|
|
|
"id,keycol,material,lotnum,producedate,expirydate,tqq9_goods,tqq9_registration"
|
2025-12-15 05:45:13 +00:00
|
|
|
|
, new QFilter[]{materielF.and(warehouseF).and(lotNumberF)});
|
2025-12-11 04:34:41 +00:00
|
|
|
|
if (null != objects && objects.length > 0) {
|
|
|
|
|
|
if (objects.length == 1) {
|
|
|
|
|
|
DynamicObject object = objects[0];
|
2025-12-15 05:45:13 +00:00
|
|
|
|
Date producedate = object.getDate("producedate");//生产日期
|
|
|
|
|
|
Date expirydate = object.getDate("expirydate");//失效日期
|
|
|
|
|
|
DynamicObject tqq9_registration = object.getDynamicObject("tqq9_registration");//注册证
|
|
|
|
|
|
DynamicObject tqq9_goods = object.getDynamicObject("tqq9_goods");//商品
|
2025-12-11 04:34:41 +00:00
|
|
|
|
StringBuilder tqq9_cs = new StringBuilder();
|
|
|
|
|
|
StringBuilder tqq9_licenseno = new StringBuilder();
|
|
|
|
|
|
if (null != tqq9_registration) {
|
|
|
|
|
|
tqq9_registration = BusinessDataServiceHelper.loadSingle("tqq9_registration",
|
|
|
|
|
|
"id,number,tqq9_entry.tqq9_e_supplier,tqq9_entry.tqq9_e_supno,tqq9_proxy,tqq9_proxyno"
|
|
|
|
|
|
, new QFilter[]{new QFilter("id", QCP.equals, tqq9_registration.getLong("id"))});
|
|
|
|
|
|
DynamicObjectCollection tqq9_entry = tqq9_registration.getDynamicObjectCollection("tqq9_entry");
|
|
|
|
|
|
for (int i = 0; i < tqq9_entry.size(); i++) {
|
|
|
|
|
|
DynamicObject dynamicObject = tqq9_entry.get(i);
|
|
|
|
|
|
DynamicObject tqq9_e_supplier = dynamicObject.getDynamicObject("tqq9_e_supplier");
|
|
|
|
|
|
if (null != tqq9_e_supplier) {
|
|
|
|
|
|
tqq9_cs.append(tqq9_e_supplier.getString("name"));
|
|
|
|
|
|
if (i != tqq9_entry.size() - 1) {
|
|
|
|
|
|
tqq9_cs.append("#");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
String tqq9_e_supno = dynamicObject.getString("tqq9_e_supno");
|
|
|
|
|
|
if (StringUtils.isNotBlank(tqq9_e_supno)) {
|
|
|
|
|
|
tqq9_licenseno.append(tqq9_e_supno);
|
|
|
|
|
|
if (i != tqq9_entry.size() - 1) {
|
|
|
|
|
|
tqq9_licenseno.append("#");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
this.getModel().setValue("tqq9_producedate", producedate, rowIndex);
|
2025-12-15 05:45:13 +00:00
|
|
|
|
this.getModel().setValue("tqq9_goods", tqq9_goods, rowIndex);
|
2025-12-11 04:34:41 +00:00
|
|
|
|
this.getModel().setValue("tqq9_expirydate", expirydate, rowIndex);
|
|
|
|
|
|
this.getModel().setValue("tqq9_cs", tqq9_cs.toString(), rowIndex);
|
|
|
|
|
|
this.getModel().setValue("tqq9_licenseno", tqq9_licenseno.toString(), rowIndex);
|
|
|
|
|
|
this.getModel().setValue("tqq9_zczh", tqq9_registration, rowIndex);
|
2025-12-15 05:45:13 +00:00
|
|
|
|
}else{
|
|
|
|
|
|
this.getModel().setValue("tqq9_producedate", null, rowIndex);
|
|
|
|
|
|
this.getModel().setValue("tqq9_goods", null, rowIndex);
|
|
|
|
|
|
this.getModel().setValue("tqq9_expirydate", null, rowIndex);
|
|
|
|
|
|
this.getModel().setValue("tqq9_cs", null, rowIndex);
|
|
|
|
|
|
this.getModel().setValue("tqq9_licenseno", null, rowIndex);
|
|
|
|
|
|
this.getModel().setValue("tqq9_zczh", null, rowIndex);
|
2025-12-11 04:34:41 +00:00
|
|
|
|
}
|
2025-12-15 05:45:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-09 08:38:22 +00:00
|
|
|
|
|
2025-12-15 05:45:13 +00:00
|
|
|
|
String sql="/*dialect*/SELECT \n" +
|
|
|
|
|
|
" t1.fmaterialid, \n" +
|
|
|
|
|
|
" t1.fwarehouseid,\n" +
|
|
|
|
|
|
" t1.flotnum,\n" +
|
|
|
|
|
|
" SUM(t1.fqty) - COALESCE(SUM(t2.f_qty), 0) AS qty_difference\n" +
|
|
|
|
|
|
"FROM \n" +
|
|
|
|
|
|
" (SELECT fmaterialid, fwarehouseid, flotnum, SUM(fqty) AS fqty\n" +
|
|
|
|
|
|
" FROM t_im_inv_realbalance\n" +
|
|
|
|
|
|
" GROUP BY fmaterialid, fwarehouseid, flotnum) t1\n" +
|
|
|
|
|
|
"LEFT JOIN \n" +
|
|
|
|
|
|
" (SELECT f_s_materiel, f_s_warehouse, f_s_lotnum, SUM(f_qty) AS f_qty\n" +
|
|
|
|
|
|
" FROM t_msmod_reserverecord\n" +
|
|
|
|
|
|
" GROUP BY f_s_materiel, f_s_warehouse, f_s_lotnum) t2\n" +
|
|
|
|
|
|
"ON t1.fmaterialid = t2.f_s_materiel \n" +
|
|
|
|
|
|
" AND t1.fwarehouseid = t2.f_s_warehouse\n" +
|
|
|
|
|
|
" AND t1.flotnum = t2.f_s_lotnum\n" +
|
|
|
|
|
|
" WHERE \n" +
|
|
|
|
|
|
" t1.fmaterialid = "+materiel.getDynamicObject("masterid").getString("id")+"\n" +
|
|
|
|
|
|
" AND t1.fwarehouseid = "+dcck.getString("id")+" \n" +
|
|
|
|
|
|
" AND t1.flotnum = '"+lotNumber+"' \n" +
|
|
|
|
|
|
"GROUP BY t1.fmaterialid, t1.fwarehouseid, t1.flotnum;\n";
|
|
|
|
|
|
|
|
|
|
|
|
DataSet materialDataSet = DB.queryDataSet(this.getClass().getName(), DBRoute.of("scm"), sql);
|
|
|
|
|
|
DataSet copy1 = materialDataSet.copy();
|
|
|
|
|
|
DynamicObjectCollection dynamicObjects = ORM.create().toPlainDynamicObjectCollection(copy1);
|
|
|
|
|
|
if (dynamicObjects.size()>0) {
|
|
|
|
|
|
BigDecimal total_qty = dynamicObjects.get(0).getBigDecimal("qty_difference");
|
|
|
|
|
|
this.getModel().setValue("tqq9_pckyamount", total_qty, rowIndex);
|
2025-12-11 04:34:41 +00:00
|
|
|
|
}
|
2025-12-15 05:45:13 +00:00
|
|
|
|
}else if(materiel != null && dcck != null && StringUtils.isBlank(lotNumber)){
|
2025-12-11 04:34:41 +00:00
|
|
|
|
|
2025-12-15 05:45:13 +00:00
|
|
|
|
String sql="/*dialect*/SELECT \n" +
|
|
|
|
|
|
" t1.fmaterialid, \n" +
|
|
|
|
|
|
" t1.fwarehouseid,\n" +
|
|
|
|
|
|
" SUM(t1.fqty) - COALESCE(SUM(t2.f_qty), 0) AS qty_difference\n" +
|
|
|
|
|
|
"FROM \n" +
|
|
|
|
|
|
" (SELECT fmaterialid, fwarehouseid, SUM(fqty) AS fqty\n" +
|
|
|
|
|
|
" FROM t_im_inv_realbalance\n" +
|
|
|
|
|
|
" GROUP BY fmaterialid, fwarehouseid) t1\n" +
|
|
|
|
|
|
"LEFT JOIN \n" +
|
|
|
|
|
|
" (SELECT f_s_materiel, f_s_warehouse, SUM(f_qty) AS f_qty\n" +
|
|
|
|
|
|
" FROM t_msmod_reserverecord\n" +
|
|
|
|
|
|
" GROUP BY f_s_materiel, f_s_warehouse) t2\n" +
|
|
|
|
|
|
"ON t1.fmaterialid = t2.f_s_materiel \n" +
|
|
|
|
|
|
" AND t1.fwarehouseid = t2.f_s_warehouse\n" +
|
|
|
|
|
|
" WHERE \n" +
|
|
|
|
|
|
" t1.fmaterialid = "+materiel.getDynamicObject("masterid").getString("id")+"\n" +
|
|
|
|
|
|
" AND t1.fwarehouseid = "+dcck.getString("id")+" \n" +
|
|
|
|
|
|
"GROUP BY t1.fmaterialid, t1.fwarehouseid;\n";
|
|
|
|
|
|
DataSet materialDataSet = DB.queryDataSet(this.getClass().getName(), DBRoute.of("scm"), sql);
|
|
|
|
|
|
DataSet copy1 = materialDataSet.copy();
|
|
|
|
|
|
DynamicObjectCollection dynamicObjects = ORM.create().toPlainDynamicObjectCollection(copy1);
|
|
|
|
|
|
if (dynamicObjects.size()>0) {
|
|
|
|
|
|
BigDecimal total_qty = dynamicObjects.get(0).getBigDecimal("qty_difference");
|
|
|
|
|
|
this.getModel().setValue("tqq9_pckyamount", total_qty, rowIndex);
|
|
|
|
|
|
}
|
2025-12-11 04:34:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-09-19 08:50:17 +00:00
|
|
|
|
|
2025-12-15 05:45:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-09 08:38:22 +00:00
|
|
|
|
}
|