出库单添加计算金额和结算金额逻辑

This commit is contained in:
xuhaihui 2025-09-21 18:07:49 +08:00
parent e066d90d6f
commit 321336d154
1 changed files with 54 additions and 0 deletions

View File

@ -16,6 +16,7 @@ import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper; import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.user.UserServiceHelper; import kd.bos.servicehelper.user.UserServiceHelper;
import java.math.BigDecimal;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.EventObject; import java.util.EventObject;
import java.util.List; import java.util.List;
@ -26,6 +27,7 @@ import java.util.List;
* 2使用设备过滤通过核算组织与使用设备中的使用组织比对而来过滤 * 2使用设备过滤通过核算组织与使用设备中的使用组织比对而来过滤
* 3科目属性过滤和成本分解结构必录逻辑控制废弃 * 3科目属性过滤和成本分解结构必录逻辑控制废弃
* 4申请人部门赋值过滤 * 4申请人部门赋值过滤
* 5:计算金额和结算金额
*/ */
public class MaterialOutBillPlugin extends AbstractBillPlugIn implements BeforeF7SelectListener { public class MaterialOutBillPlugin extends AbstractBillPlugIn implements BeforeF7SelectListener {
@ -133,6 +135,58 @@ public class MaterialOutBillPlugin extends AbstractBillPlugIn implements BeforeF
} else { } else {
this.getModel().setValue("zcgj_applidepart", null);//清空申请人部门字段 this.getModel().setValue("zcgj_applidepart", null);//清空申请人部门字段
} }
} else if ("qty".equals(key)) {
//数量
ChangeData[] changeSet = e.getChangeSet();
ChangeData changeData = changeSet[0];
DynamicObject dataEntity = changeData.getDataEntity();
int rowIndex = changeData.getRowIndex();
BigDecimal newValue = (BigDecimal) changeData.getNewValue();//数量
BigDecimal price = dataEntity.getBigDecimal("price");//单价不含税
BigDecimal settleprice = dataEntity.getBigDecimal("settleprice");//结算单价
this.getModel().setValue("amount", newValue.multiply(price), rowIndex);//金额
this.getModel().setValue("settleamount", newValue.multiply(settleprice), rowIndex);//结算金额
Object warehouse = this.getModel().getValue("warehouse");//发货仓库
DynamicObject transType = (DynamicObject) this.getModel().getValue("transtype");//事务类型
DynamicObject org = (DynamicObject) this.getModel().getValue("org");//事务类型
DynamicObject material = dataEntity.getDynamicObject("material");//资源编码
if (warehouse != null && transType != null && "REDUCE".equals(transType.getString("type")) && org != null && material != null) {
DynamicObject warehouse1 = (DynamicObject) warehouse;//发货仓库
DynamicObject project = warehouse1.getDynamicObject("project");//发货仓库-项目
QFilter qFilters = new QFilter("warehouse", QCP.equals, warehouse1.getPkValue());
if (project != null) {
qFilters.and(new QFilter("project", QCP.equals, project.getPkValue()));//即时库存-项目
}
qFilters.and(new QFilter("org", QCP.equals, org.getPkValue()));//即时库存-所属组织
qFilters.and(new QFilter("material", QCP.equals, material.getPkValue()));//即时库存-资源名称
DynamicObject ecma_matinventory = BusinessDataServiceHelper.loadSingle("ecma_matinventory", new QFilter[]{qFilters});//即时库存
if (ecma_matinventory != null) {
BigDecimal qty = ecma_matinventory.getBigDecimal("qty");//即时库存-可用数量
DynamicObjectCollection entryEntityCollection = this.getModel().getDataEntity(true).getDynamicObjectCollection("entryentity");//出库单分录
BigDecimal totalQty = BigDecimal.ZERO;//修改行相同的资源编码数量
BigDecimal totalAmount = BigDecimal.ZERO;//修改行不相同的资源编码数量
for (int i = 0; i < entryEntityCollection.size(); i++) {
DynamicObject entryEntity = entryEntityCollection.get(i);
DynamicObject material1 = entryEntity.getDynamicObject("material");//出库单分录-资源编码
BigDecimal qty1 = entryEntity.getBigDecimal("qty");//出库单分录-数量
BigDecimal amount = entryEntity.getBigDecimal("amount");//出库单分录-金额
if (material1 == null) {
continue;
}
if (!material.getPkValue().equals(material1.getPkValue())) {
continue;
}
totalQty = totalQty.add(qty1);
if (rowIndex == i){
continue;
}
totalAmount = totalAmount.add(amount);
}
if (totalQty.compareTo(qty) == 0) {
this.getModel().setValue("amount", ecma_matinventory.getBigDecimal("amount").subtract(totalAmount), rowIndex);//金额
}
}
}
} }
} }