异地退货

This commit is contained in:
sez 2025-11-20 11:27:59 +08:00
parent 21cd42d284
commit 79a5bf13e4
3 changed files with 304 additions and 5 deletions

View File

@ -68,11 +68,13 @@ public class PurRefundApplyFormPlugin extends AbstractBillPlugIn implements Befo
addNew.set("tqq9_registration_ydth", dynamicObject.get("tqq9_registration")); addNew.set("tqq9_registration_ydth", dynamicObject.get("tqq9_registration"));
addNew.set("tqq9_licenseno_ydth", dynamicObject.get("tqq9_licenseno")); addNew.set("tqq9_licenseno_ydth", dynamicObject.get("tqq9_licenseno"));
addNew.set("tqq9_priceandtax_ydth", dynamicObject.get("priceandtax")); addNew.set("tqq9_priceandtax_ydth", dynamicObject.get("priceandtax"));
addNew.set("tqq9_amountandtax_ydth", dynamicObject.get("amountandtax")); //addNew.set("tqq9_amountandtax_ydth", dynamicObject.get("amountandtax"));
addNew.set("tqq9_ph_ydth", dynamicObject.get("tqq9_ph")); addNew.set("tqq9_ph_ydth", dynamicObject.get("tqq9_ph"));
addNew.set("tqq9_productdate_ydth", dynamicObject.get("tqq9_productdate")); addNew.set("tqq9_productdate_ydth", dynamicObject.get("tqq9_productdate"));
addNew.set("tqq9_expiredate_ydth", dynamicObject.get("tqq9_expiredate")); addNew.set("tqq9_expiredate_ydth", dynamicObject.get("tqq9_expiredate"));
addNew.set("tqq9_cgthflid", dynamicObject.get("id")); addNew.set("tqq9_cgthflid", dynamicObject.get("id"));
addNew.set("tqq9_price_ydth", dynamicObject.get("price"));
addNew.set("tqq9_taxrateid_ydth", dynamicObject.get("taxrateid"));
this.getModel().updateEntryCache(tqq9_entryentity); this.getModel().updateEntryCache(tqq9_entryentity);
this.getView().updateView("tqq9_entryentity"); this.getView().updateView("tqq9_entryentity");

View File

@ -36,6 +36,7 @@ public class OtherInYdthPlugin extends AbstractOperationServicePlugIn implements
public void onPreparePropertys(PreparePropertysEventArgs e) { public void onPreparePropertys(PreparePropertysEventArgs e) {
super.onPreparePropertys(e); super.onPreparePropertys(e);
e.getFieldKeys().add("billentry.tqq9_cgthflid"); e.getFieldKeys().add("billentry.tqq9_cgthflid");
e.getFieldKeys().add("billentry.tqq9_ydthflid");//异地退货分录id
} }
@Override @Override
@ -68,6 +69,7 @@ public class OtherInYdthPlugin extends AbstractOperationServicePlugIn implements
String returnEntryId = inEntry.getString("tqq9_cgthflid"); String returnEntryId = inEntry.getString("tqq9_cgthflid");
BigDecimal qty = inEntry.getBigDecimal("qty") == null ? BigDecimal.ZERO : inEntry.getBigDecimal("qty"); // 入库数量 BigDecimal qty = inEntry.getBigDecimal("qty") == null ? BigDecimal.ZERO : inEntry.getBigDecimal("qty"); // 入库数量
String materialId = inEntry.getDynamicObject("material").getDynamicObject("masterid").getString("id"); String materialId = inEntry.getDynamicObject("material").getDynamicObject("masterid").getString("id");
long tqq9_ydthflid = inEntry.getLong("tqq9_ydthflid");
if (returnEntryId != null && qty != null && materialId != null) { if (returnEntryId != null && qty != null && materialId != null) {
// 创建数据Map收集明细信息 // 创建数据Map收集明细信息
@ -75,12 +77,36 @@ public class OtherInYdthPlugin extends AbstractOperationServicePlugIn implements
redEntryData.put("materialId", materialId); redEntryData.put("materialId", materialId);
redEntryData.put("qty", qty); // 红字用负数 redEntryData.put("qty", qty); // 红字用负数
redEntryData.put("returnEntryId", returnEntryId); redEntryData.put("returnEntryId", returnEntryId);
redEntryData.put("tqq9_ydthflid", tqq9_ydthflid);
redEntryDataList.add(redEntryData); redEntryDataList.add(redEntryData);
} }
} }
DynamicObjectCollection tqq9_entryentity = pm_purrefundapplybill.getDynamicObjectCollection("tqq9_entryentity");//异地退货明细
for (Map<String, Object> map : redEntryDataList) {
for (DynamicObject object : tqq9_entryentity) {
long id = object.getLong("id");
long tqq9_ydthflid = (long) map.get("tqq9_ydthflid");
if (id == tqq9_ydthflid) {
DynamicObject tqq9_taxrateid_ydth = object.getDynamicObject("tqq9_taxrateid_ydth");
if (null != tqq9_taxrateid_ydth) {
map.put("tqq9_taxrateid_ydth", tqq9_taxrateid_ydth.getLong("id"));//税率
}
map.put("tqq9_price_ydth", object.get("tqq9_price_ydth"));//不含税单价
map.put("tqq9_taxamount_ydth", object.get("tqq9_taxamount_ydth"));//税额
map.put("tqq9_priceandtax_ydth", object.get("tqq9_priceandtax_ydth"));//含税单价
map.put("tqq9_amountandtax_ydth", object.get("tqq9_amountandtax_ydth"));//折扣后价税合计
map.put("tqq9_amount_ydth", object.get("tqq9_amount_ydth"));//折扣后不含税金额
break;
}
}
}
Long id = pm_purrefundapplybill.getLong("id"); Long id = pm_purrefundapplybill.getLong("id");
Map<String, Set<JSONObject>> param = new HashMap<>();//传入转换规则处理参数 Map<String, Set<JSONObject>> param = new HashMap<>();//传入转换规则处理参数
@ -89,10 +115,17 @@ public class OtherInYdthPlugin extends AbstractOperationServicePlugIn implements
Object materialId = map.get("materialId"); Object materialId = map.get("materialId");
Object qty = map.get("qty"); Object qty = map.get("qty");
Object returnEntryId = map.get("returnEntryId"); Object returnEntryId = map.get("returnEntryId");
detailObject.put("materialId", materialId); Object tqq9_ydthflid = map.get("tqq9_ydthflid");
detailObject.put("qty", qty); detailObject.put("materialId", materialId);//物料id
detailObject.put("returnEntryId", returnEntryId); detailObject.put("qty", qty);//数量
detailObject.put("returnEntryId", returnEntryId);//采购退货明细id
detailObject.put("tqq9_ydthflid", tqq9_ydthflid);//异地退货分录id
detailObject.put("tqq9_taxrateid_ydth", map.get("tqq9_taxrateid_ydth"));//税率
detailObject.put("tqq9_price_ydth", map.get("tqq9_price_ydth"));//不含税单价
detailObject.put("tqq9_taxamount_ydth", map.get("tqq9_taxamount_ydth"));//税额
detailObject.put("tqq9_priceandtax_ydth", map.get("tqq9_priceandtax_ydth"));//含税单价
detailObject.put("tqq9_amountandtax_ydth", map.get("tqq9_amountandtax_ydth"));//折扣后价税合计
detailObject.put("tqq9_amount_ydth", map.get("tqq9_amount_ydth"));//折扣后不含税金额
param.computeIfAbsent((String) returnEntryId, k -> new HashSet<>()).add(detailObject); param.computeIfAbsent((String) returnEntryId, k -> new HashSet<>()).add(detailObject);
} }

View File

@ -0,0 +1,264 @@
package tqq9.lc123.cloud.app.plugin.operate.im;
import com.alibaba.nacos.common.utils.StringUtils;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.dataentity.metadata.IDataEntityProperty;
import kd.bos.dataentity.metadata.clr.DataEntityPropertyCollection;
import kd.bos.entity.ExtendedDataEntity;
import kd.bos.entity.ExtendedDataEntitySet;
import kd.bos.entity.botp.plugin.AbstractConvertPlugIn;
import kd.bos.entity.botp.plugin.args.AfterConvertEventArgs;
import kd.bos.entity.botp.runtime.ConvertConst;
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 java.math.BigDecimal;
import java.util.*;
/**
* 采购入库转换插件
*/
public class YdthPurInConvertPlugin extends AbstractConvertPlugIn implements Plugin {
private final static Log logger = LogFactory.getLog(YdthPurInConvertPlugin.class);
private static String IM_PURINBILL = "im_purinbill";
private final static HashMap<String, String> wareTypeMap = new HashMap<String, String>() {{
put("地堆区", "SHZC01");
put("存储区", "SHZC01");
put("立库区", "SHZC01");
put("新仓", "SHZC01");
put("破损区", "SHZC02");
put("零拣区", "SHZC02");
put("收货中转", "SHZC03");
put("退货中转", "SHZC03");
put("虚拟区", "SHZC03");
}};
/**
* 入库回传下推写入对应的
* quantity 入库数量
* manufactureDate 生产日期
* expirationDate 失效期
* batch 批次
* registrationCode 注册证号
* licenceCode 生产许可证号
* producer 生产厂商
*
* @param e
*/
@Override
public void afterConvert(AfterConvertEventArgs e) {
super.afterConvert(e);
ExtendedDataEntitySet targetExtDataEntitySet = e.getTargetExtDataEntitySet();
ExtendedDataEntity[] extendedDataEntities = targetExtDataEntitySet.FindByEntityKey(IM_PURINBILL);
ExtendedDataEntity[] entities = targetExtDataEntitySet.FindByEntityKey(getTgtMainType().getName());
List<DynamicObject> srcRows = (List<DynamicObject>) entities[0].getValue(ConvertConst.ConvExtDataKey_SourceRows);
DynamicObject srcRow = srcRows.get(0);
Object sourceBillPK = e.getFldProperties().get("id").getValue(srcRow);
DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle("pm_purrefundapplybill",
new QFilter[]{new QFilter("id", QCP.equals, sourceBillPK)});//采购退货申请单
boolean tqq9_isydth = dynamicObject.getBoolean("tqq9_isydth");//是否异地退货
Map<String, String> variables = this.getOption().getVariables();
if (!tqq9_isydth) {
for (ExtendedDataEntity extendedDataEntity : extendedDataEntities) {
//采购入库单
DynamicObject dataEntity = extendedDataEntity.getDataEntity();
DynamicObjectCollection dynamicObjectCollection = dataEntity.getDynamicObjectCollection("billentry");
ListIterator<DynamicObject> iterator = dynamicObjectCollection.listIterator();
while (iterator.hasNext()) {
DynamicObject entry = iterator.next();
String srcbillentryid = entry.getString("srcbillentryid");
//核心单据号一致写入数据
if (variables.containsKey(srcbillentryid)) {
String jsonString = variables.get(srcbillentryid);
ObjectMapper objectMapper = new ObjectMapper();
List<HashMap<String, Object>> jsonList = null;
try {
jsonList = objectMapper.readValue(jsonString, objectMapper.getTypeFactory().constructCollectionType(List.class, HashMap.class));
} catch (JsonProcessingException ex) {
throw new RuntimeException(ex);
}
if (jsonList != null) {
dataEntity.set("tqq9_isrebulidlink", true);
for (int i = 0; i < jsonList.size(); i++) {
HashMap<String, Object> jsonMap = jsonList.get(i);
String VoucherType = jsonMap.get("VoucherType").toString();//类型
Date manufactureDate = null;
Date expirationDate = null;
if (jsonMap.get("manufactureDate") instanceof Long) {
manufactureDate = new Date((Long) jsonMap.get("manufactureDate")); //生产日期
}
if (jsonMap.get("expirationDate") instanceof Long) {
expirationDate = new Date((Long) jsonMap.get("expirationDate")); //生产日期
}
BigDecimal quantity = BigDecimal.ZERO;
if (StringUtils.equals("pm_receiptnotice", VoucherType)) {
quantity = new BigDecimal(jsonMap.get("quantity").toString());//入库数量
} else {
quantity = new BigDecimal(jsonMap.get("quantity").toString()).negate();//入库数量
}
String batch = jsonMap.get("batch") != null ? jsonMap.get("batch").toString() : null; // 批次
String toZone = jsonMap.get("toZone") != null ? jsonMap.get("toZone").toString() : null; // 库区
DynamicObject bd_warehouse = null;
if (toZone != null) {
String wareNumber = wareTypeMap.get(toZone);
bd_warehouse = BusinessDataServiceHelper.loadSingle("bd_warehouse", new QFilter[]{new QFilter("number", QCP.equals, wareNumber)});
}
String wmsDetailId = jsonMap.get("wmsDetailId") != null ? jsonMap.get("wmsDetailId").toString() : null; // WMS分录id
String uniqueCode = jsonMap.get("uniqueCode") != null ? jsonMap.get("uniqueCode").toString() : null; // 商品编码
String registrationCode = jsonMap.get("registrationCode") != null ? jsonMap.get("registrationCode").toString() : null; // 注册证号
String licenceCode = jsonMap.get("licenceCode") != null ? jsonMap.get("licenceCode").toString() : null; // 生产许可证号
String producer = jsonMap.get("producer") != null ? jsonMap.get("producer").toString() : null; // 生产厂商
DynamicObject tqq9_goodspackage = BusinessDataServiceHelper.loadSingle("tqq9_goodspackage", new QFilter[]{new QFilter("tqq9_mater.number", QCP.equals, uniqueCode).and("tqq9_isauto", QCP.equals, true)});
DynamicObject tqq9_registration = BusinessDataServiceHelper.loadSingle("tqq9_registration", new QFilter[]{new QFilter("number", QCP.equals, registrationCode)});
DynamicObject tqq9_proxyandfactory = BusinessDataServiceHelper.loadSingle("tqq9_proxyandfactory", new QFilter[]{new QFilter("number", QCP.equals, producer)});
// 处理第一次逻辑
if (i == 0) {
// 第一次直接赋值
entry.set("qty", quantity);
entry.set("baseqty", quantity);
entry.set("tqq9_goods", tqq9_goodspackage);
entry.set("producedate", manufactureDate);
entry.set("expirydate", expirationDate);
entry.set("lotnumber", batch);
if (null != bd_warehouse) {
entry.set("warehouse", bd_warehouse);
}
entry.set("tqq9_wmsdetailid", wmsDetailId);
entry.set("tqq9_licenseno", licenceCode);
entry.set("tqq9_registration", tqq9_registration);
entry.set("tqq9_proxyandfactory", tqq9_proxyandfactory);
DynamicObjectCollection billentry_lk = entry.getDynamicObjectCollection("billentry_lk");
billentry_lk.clear();
} else {
DataEntityPropertyCollection properties = entry.getDataEntityType().getProperties();
// 后续循环复制entry并赋值
DynamicObject newEntry = new DynamicObject(dynamicObjectCollection.getDynamicObjectType());
for (IDataEntityProperty property : properties) {
newEntry.set(property.getName(), entry.get(property.getName()));
}
newEntry.set("qty", quantity);
newEntry.set("baseqty", quantity);
newEntry.set("tqq9_goods", tqq9_goodspackage);
newEntry.set("producedate", manufactureDate);
newEntry.set("expirydate", expirationDate);
newEntry.set("lotnumber", batch);
if (null != bd_warehouse) {
newEntry.set("warehouse", bd_warehouse);
}
newEntry.set("tqq9_wmsdetailid", wmsDetailId);
newEntry.set("tqq9_licenseno", licenceCode);
newEntry.set("tqq9_registration", tqq9_registration);
newEntry.set("tqq9_proxyandfactory", tqq9_proxyandfactory);
DynamicObjectCollection billentry_lk = newEntry.getDynamicObjectCollection("billentry_lk");
billentry_lk.clear();
// 处理完新entry后的逻辑比如加入集合或其他操作
iterator.add(newEntry);
}
}
}
}
}
}
} else {
for (ExtendedDataEntity extendedDataEntity : extendedDataEntities) {
//采购入库单
DynamicObject dataEntity = extendedDataEntity.getDataEntity();
DynamicObjectCollection dynamicObjectCollection = dataEntity.getDynamicObjectCollection("billentry");
ListIterator<DynamicObject> iterator = dynamicObjectCollection.listIterator();
while (iterator.hasNext()) {
DynamicObject entry = iterator.next();
String srcbillentryid = entry.getString("srcbillentryid");
//核心单据号一致写入数据
if (variables.containsKey(srcbillentryid)) {
String jsonString = variables.get(srcbillentryid);
ObjectMapper objectMapper = new ObjectMapper();
List<HashMap<String, Object>> jsonList = null;
try {
jsonList = objectMapper.readValue(jsonString, objectMapper.getTypeFactory().constructCollectionType(List.class, HashMap.class));
} catch (JsonProcessingException ex) {
throw new RuntimeException(ex);
}
if (jsonList != null) {
dataEntity.set("tqq9_isrebulidlink", true);
for (int i = 0; i < jsonList.size(); i++) {
HashMap<String, Object> jsonMap = jsonList.get(i);
Object materialId = jsonMap.get("materialId");
Object qty = jsonMap.get("qty");
Object returnEntryId = jsonMap.get("returnEntryId");
Object tqq9_ydthflid = jsonMap.get("tqq9_ydthflid");
Object tqq9_taxrateid_ydth = jsonMap.get("tqq9_taxrateid_ydth");//税率
DynamicObject bd_taxrate = BusinessDataServiceHelper.loadSingle("bd_taxrate",
new QFilter[]{new QFilter("id", QCP.equals, tqq9_taxrateid_ydth)});
Object tqq9_price_ydth = jsonMap.get("tqq9_price_ydth");//不含税单价
Object tqq9_taxamount_ydth = jsonMap.get("tqq9_taxamount_ydth");//税额
Object tqq9_priceandtax_ydth = jsonMap.get("tqq9_priceandtax_ydth");//含税单价
Object tqq9_amountandtax_ydth = jsonMap.get("tqq9_amountandtax_ydth");//折扣后价税合计
Object tqq9_amount_ydth = jsonMap.get("tqq9_amount_ydth");//折扣后不含税金额
// 处理第一次逻辑
if (i == 0) {
// 第一次直接赋值
entry.set("qty", qty);
entry.set("remainreturnqty", qty);//未退库数量
entry.set("remainreturnbaseqty", qty);//未退库基本数量
entry.set("remainjoinpriceqty", qty); //剩余应付数量
entry.set("remainjoinpricebaseqty", qty);//剩余应付基本数量
entry.set("unverifyqty", qty); //未核销数量
entry.set("unverifybaseqty", qty); //未核销基本数量
entry.set("taxrateid", bd_taxrate);//税率
entry.set("price", tqq9_price_ydth);//不含税单价
entry.set("taxamount", tqq9_taxamount_ydth);//税额
entry.set("priceandtax", tqq9_priceandtax_ydth);//含税单价
entry.set("amountandtax", tqq9_amountandtax_ydth);//折扣后价税合计
entry.set("amount", tqq9_amount_ydth);//折扣后不含税金额
DynamicObjectCollection billentry_lk = entry.getDynamicObjectCollection("billentry_lk");
billentry_lk.clear();
} else {
DataEntityPropertyCollection properties = entry.getDataEntityType().getProperties();
// 后续循环复制entry并赋值
DynamicObject newEntry = new DynamicObject(dynamicObjectCollection.getDynamicObjectType());
for (IDataEntityProperty property : properties) {
newEntry.set(property.getName(), entry.get(property.getName()));
}
newEntry.set("qty", qty);
newEntry.set("remainreturnqty", qty);//未退库数量
newEntry.set("remainreturnbaseqty", qty);//未退库基本数量
newEntry.set("remainjoinpriceqty", qty); //剩余应付数量
newEntry.set("remainjoinpricebaseqty", qty);//剩余应付基本数量
newEntry.set("unverifyqty", qty); //未核销数量
newEntry.set("unverifybaseqty", qty); //未核销基本数量
newEntry.set("taxrateid", bd_taxrate);//税率
newEntry.set("price", tqq9_price_ydth);//不含税单价
newEntry.set("taxamount", tqq9_taxamount_ydth);//税额
newEntry.set("priceandtax", tqq9_priceandtax_ydth);//含税单价
newEntry.set("amountandtax", tqq9_amountandtax_ydth);//折扣后价税合计
newEntry.set("amount", tqq9_amount_ydth);//折扣后不含税金额
DynamicObjectCollection billentry_lk = newEntry.getDynamicObjectCollection("billentry_lk");
billentry_lk.clear();
// 处理完新entry后的逻辑比如加入集合或其他操作
iterator.add(newEntry);
}
}
}
}
}
}
}
}
}