2025-08-29 10:01:57 +00:00
|
|
|
package tqq9.lc123.cloud.app.plugin.utils;
|
|
|
|
|
|
|
|
|
|
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 java.math.BigDecimal;
|
2025-09-01 08:50:23 +00:00
|
|
|
import java.math.RoundingMode;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
2025-12-24 05:55:21 +00:00
|
|
|
import java.util.Set;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
import java.util.stream.Stream;
|
2025-08-29 10:01:57 +00:00
|
|
|
|
|
|
|
|
public class EntryFieldRefresher {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 处理组织和字段的工具类
|
|
|
|
|
*
|
|
|
|
|
* @param org 组织参数
|
|
|
|
|
* @param entityname 字段标识
|
|
|
|
|
* @param dynamicObject 基础资料
|
2025-09-01 08:50:23 +00:00
|
|
|
* @param model 单据实体
|
2025-08-29 10:01:57 +00:00
|
|
|
*/
|
|
|
|
|
public void updateDynamicObjectByOrg(String org, String entityname, DynamicObject dynamicObject, IDataModel model) {
|
|
|
|
|
|
|
|
|
|
DynamicObjectCollection entries = model.getDataEntity(true).getDynamicObjectCollection("billentry");
|
|
|
|
|
for (int i = 0; i < entries.size(); i++) {
|
|
|
|
|
DynamicObject entry = entries.get(i);
|
|
|
|
|
DynamicObject entryrecorg = entry.getDynamicObject("entryrecorg");//收货组织
|
|
|
|
|
if (StringUtils.equals(org, entryrecorg.getString("number"))) {
|
|
|
|
|
model.setValue(entityname, dynamicObject, i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-01 08:50:23 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 处理组织和字段的工具类
|
|
|
|
|
*
|
|
|
|
|
* @param org 组织参数
|
|
|
|
|
* @param entityname 字段标识
|
|
|
|
|
* @param sum_entityname 单头金额
|
|
|
|
|
* @param model 单据实体
|
|
|
|
|
*/
|
|
|
|
|
public void sumEntrByOrg(String org, String entityname, String sum_entityname, IDataModel model) {
|
|
|
|
|
|
|
|
|
|
DynamicObjectCollection entries = model.getDataEntity(true).getDynamicObjectCollection("billentry");
|
|
|
|
|
BigDecimal sum =BigDecimal.ZERO;
|
|
|
|
|
for (int i = 0; i < entries.size(); i++) {
|
|
|
|
|
DynamicObject entry = entries.get(i);
|
|
|
|
|
DynamicObject entryrecorg = entry.getDynamicObject("entryrecorg");//收货组织
|
|
|
|
|
BigDecimal qty = entry.getBigDecimal(entityname);//分录字段值
|
|
|
|
|
if (StringUtils.equals(org, entryrecorg.getString("number"))&&qty!=null) {
|
|
|
|
|
sum = sum.add(qty);
|
|
|
|
|
}
|
|
|
|
|
model.setValue(sum_entityname,sum);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-29 10:01:57 +00:00
|
|
|
/**
|
|
|
|
|
* 处理组织和字段的工具类
|
|
|
|
|
*
|
|
|
|
|
* @param org 组织参数
|
|
|
|
|
* @param entityname 字段标识
|
|
|
|
|
* @param amount 金额
|
2025-09-01 08:50:23 +00:00
|
|
|
* @param model 单据实体
|
2025-08-29 10:01:57 +00:00
|
|
|
*/
|
|
|
|
|
public void updateAmountByOrg(String org, String entityname, BigDecimal amount, IDataModel model) {
|
2025-09-03 09:49:27 +00:00
|
|
|
if (amount.compareTo(BigDecimal.ZERO) >= 0) {
|
2025-09-01 08:50:23 +00:00
|
|
|
DynamicObjectCollection entries = model.getDataEntity(true).getDynamicObjectCollection("billentry");
|
|
|
|
|
if (entries != null && entries.size() > 0) {
|
|
|
|
|
BigDecimal remainRefundAmt = amount;//拆分后剩余的金额
|
|
|
|
|
List<Integer> seqs = new ArrayList<>();
|
|
|
|
|
BigDecimal tqq9_totalamount = BigDecimal.ZERO;
|
|
|
|
|
for (int i = 0; i <= entries.size() - 1; i++) {
|
|
|
|
|
DynamicObject entry = entries.get(i);
|
|
|
|
|
DynamicObject entryrecorg = entry.getDynamicObject("entryrecorg");//收货组织
|
|
|
|
|
if (StringUtils.equals(org, entryrecorg.getString("number"))) {
|
2025-12-19 09:25:33 +00:00
|
|
|
BigDecimal tqq9_pricecj = entry.getBigDecimal("tqq9_pricecj");//价税合计
|
|
|
|
|
tqq9_totalamount = tqq9_totalamount.add(tqq9_pricecj);
|
|
|
|
|
if (tqq9_pricecj.compareTo(BigDecimal.ZERO) > 0) {
|
2025-09-01 08:50:23 +00:00
|
|
|
seqs.add(i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for (int i = 0; i <= seqs.size() - 1; i++) {
|
|
|
|
|
int seq = seqs.get(i);
|
|
|
|
|
if (i == seqs.size() - 1) {
|
|
|
|
|
//如果是最后一行
|
|
|
|
|
model.setValue(entityname, remainRefundAmt, seq);//明细金额
|
|
|
|
|
} else {
|
|
|
|
|
//如果不是最后一行
|
2025-12-19 09:25:33 +00:00
|
|
|
BigDecimal tqq9_pricecj = (BigDecimal) model.getValue("tqq9_pricecj", seq);//价税合计
|
|
|
|
|
if (tqq9_pricecj.compareTo(BigDecimal.ZERO) == 0) {
|
2025-09-01 08:50:23 +00:00
|
|
|
model.setValue(entityname, BigDecimal.ZERO, seq);//明细金额
|
|
|
|
|
} else {
|
2025-12-19 09:25:33 +00:00
|
|
|
BigDecimal tqq9_disamount = amount.multiply(tqq9_pricecj).divide(tqq9_totalamount, 10, RoundingMode.HALF_UP);//分录行含税金额比例
|
2025-09-01 08:50:23 +00:00
|
|
|
model.setValue(entityname, tqq9_disamount, seq);//明细金额
|
|
|
|
|
remainRefundAmt = remainRefundAmt.subtract(tqq9_disamount);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-08-29 10:01:57 +00:00
|
|
|
}
|
2025-12-24 05:55:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据单据标识获取分录中物料字段名
|
|
|
|
|
* @param entityName
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public static String getEntryMaterialFieldNameByEntityName(String entityName){
|
|
|
|
|
String fieldName = null;
|
|
|
|
|
//采购订单、收货通知单、采购入库单、销售订单、发货通知单、销售出库单、其他出库单、其他入库申请单、其他入库单、形态转换单、短缺处理单
|
|
|
|
|
Set<String> materialFieldNameSet_1 = Stream.of(
|
|
|
|
|
"pm_purorderbill", "pm_receiptnotice", "im_purinbill", "sm_salorder", "sm_delivernotice", "im_saloutbill",
|
|
|
|
|
"im_otheroutbill", "tqq9_otherinapply", "im_otherinbill", "im_adjustbill", "tqq9_shortagebill")
|
|
|
|
|
.collect(Collectors.toSet());//material
|
|
|
|
|
//暂估应收单、财务应收单、付款申请单、暂估应付单、财务应付单
|
|
|
|
|
Set<String> materialFieldNameSet_2 = Stream.of(
|
|
|
|
|
"ar_busbill", "ar_finarbill", "ap_payapply", "ar_busbill", "ar_finarbill")
|
|
|
|
|
.collect(Collectors.toSet());//e_material
|
|
|
|
|
//其他出库申请单
|
|
|
|
|
Set<String> materialFieldNameSet_3 = Stream.of("tqq9_otheroutapply").collect(Collectors.toSet());//tqq9_materiel
|
|
|
|
|
if (materialFieldNameSet_1.contains(entityName)) {
|
|
|
|
|
fieldName = "material";
|
|
|
|
|
} else if (materialFieldNameSet_2.contains(entityName)) {
|
|
|
|
|
fieldName = "e_material";
|
|
|
|
|
} else if (materialFieldNameSet_3.contains(entityName)) {
|
|
|
|
|
fieldName = "tqq9_materiel";
|
|
|
|
|
}
|
|
|
|
|
return fieldName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据单据标识获取分录标识
|
|
|
|
|
* @param entityName
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public static String getEntryFieldNameByEntityName(String entityName){
|
|
|
|
|
String fieldName = null;
|
|
|
|
|
Set<String> materialFieldNameSet_1 = Stream.of(
|
|
|
|
|
"pm_purorderbill", "pm_receiptnotice", "im_purinbill", "sm_salorder", "sm_delivernotice", "im_saloutbill",
|
|
|
|
|
"im_otheroutbill", "tqq9_otherinapply", "im_otherinbill", "im_adjustbill", "tqq9_shortagebill")
|
|
|
|
|
.collect(Collectors.toSet());//billentry
|
|
|
|
|
Set<String> materialFieldNameSet_2 = Stream.of(
|
|
|
|
|
"ar_busbill", "ar_finarbill", "ap_payapply", "ar_busbill", "ar_finarbill")
|
|
|
|
|
.collect(Collectors.toSet());//entry
|
|
|
|
|
Set<String> materialFieldNameSet_3 = Stream.of("tqq9_otheroutapply").collect(Collectors.toSet());//entryentity
|
|
|
|
|
if (materialFieldNameSet_1.contains(entityName)) {
|
|
|
|
|
fieldName = "billentry";
|
|
|
|
|
} else if (materialFieldNameSet_2.contains(entityName)) {
|
|
|
|
|
fieldName = "entry";
|
|
|
|
|
} else if (materialFieldNameSet_3.contains(entityName)) {
|
|
|
|
|
fieldName = "entryentity";
|
|
|
|
|
}
|
|
|
|
|
return fieldName;
|
|
|
|
|
}
|
2025-08-29 10:01:57 +00:00
|
|
|
}
|