出库单优化
This commit is contained in:
parent
9456b11622
commit
ca1c54c379
|
|
@ -21,6 +21,7 @@ import java.math.RoundingMode;
|
|||
import java.util.ArrayList;
|
||||
import java.util.EventObject;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 出库单表单插件
|
||||
|
|
@ -152,6 +153,7 @@ public class MaterialOutBillPlugin extends AbstractBillPlugIn implements BeforeF
|
|||
DynamicObject transType = (DynamicObject) this.getModel().getValue("transtype");//事务类型
|
||||
DynamicObject org = (DynamicObject) this.getModel().getValue("org");//事务类型
|
||||
DynamicObject material = dataEntity.getDynamicObject("material");//资源编码
|
||||
String modelnum1 = dataEntity.getString("modelnum");//规格型号
|
||||
if (warehouse != null && transType != null && "REDUCE".equals(transType.getString("type")) && org != null && material != null) {
|
||||
DynamicObject warehouse1 = (DynamicObject) warehouse;//发货仓库
|
||||
DynamicObject project = warehouse1.getDynamicObject("project");//发货仓库-项目
|
||||
|
|
@ -161,7 +163,7 @@ public class MaterialOutBillPlugin extends AbstractBillPlugIn implements BeforeF
|
|||
}
|
||||
qFilters.and(new QFilter("org", QCP.equals, org.getPkValue()));//即时库存-所属组织
|
||||
qFilters.and(new QFilter("material", QCP.equals, material.getPkValue()));//即时库存-资源名称
|
||||
qFilters.and(new QFilter("modelnum", QCP.equals, dataEntity.getString("modelnum")));//即时库存-规格型号
|
||||
qFilters.and(new QFilter("modelnum", QCP.equals, modelnum1));//即时库存-规格型号
|
||||
DynamicObject ecma_matinventory = BusinessDataServiceHelper.loadSingle("ecma_matinventory", new QFilter[]{qFilters});//即时库存
|
||||
if (ecma_matinventory != null) {
|
||||
BigDecimal qty = ecma_matinventory.getBigDecimal("qty");//即时库存-可用数量
|
||||
|
|
@ -172,6 +174,7 @@ public class MaterialOutBillPlugin extends AbstractBillPlugIn implements BeforeF
|
|||
for (int i = 0; i < entryEntityCollection.size(); i++) {
|
||||
DynamicObject entryEntity = entryEntityCollection.get(i);
|
||||
DynamicObject material1 = entryEntity.getDynamicObject("material");//出库单分录-资源编码
|
||||
String modelnum = entryEntity.getString("modelnum");//出库单分录-规格型号
|
||||
BigDecimal qty1 = entryEntity.getBigDecimal("qty");//出库单分录-数量
|
||||
BigDecimal amount = entryEntity.getBigDecimal("amount");//出库单分录-金额
|
||||
if (material1 == null) {
|
||||
|
|
@ -180,6 +183,9 @@ public class MaterialOutBillPlugin extends AbstractBillPlugIn implements BeforeF
|
|||
if (!material.getPkValue().equals(material1.getPkValue())) {
|
||||
continue;
|
||||
}
|
||||
if (!Objects.equals(modelnum, modelnum1)) {
|
||||
continue;
|
||||
}
|
||||
totalQty = totalQty.add(qty1);
|
||||
if (rowIndex == i) {
|
||||
continue;
|
||||
|
|
@ -189,7 +195,7 @@ public class MaterialOutBillPlugin extends AbstractBillPlugIn implements BeforeF
|
|||
if (totalQty.compareTo(qty) == 0) {
|
||||
BigDecimal amount = ecma_matinventory.getBigDecimal("amount").subtract(totalAmount);
|
||||
this.getModel().setValue("amount", amount, rowIndex);//金额
|
||||
BigDecimal price1 = amount.divide(qty, 2, RoundingMode.HALF_UP);
|
||||
BigDecimal price1 = amount.divide(newValue, 2, RoundingMode.HALF_UP);
|
||||
this.getModel().setValue("price", price1, rowIndex);//单价(不含税)
|
||||
} else {
|
||||
this.getModel().setValue("price", price2, rowIndex);//单价(不含税)
|
||||
|
|
@ -205,22 +211,86 @@ public class MaterialOutBillPlugin extends AbstractBillPlugIn implements BeforeF
|
|||
public void itemClick(ItemClickEvent evt) {
|
||||
super.itemClick(evt);
|
||||
String itemKey = evt.getItemKey();
|
||||
// if (itemKey.equals("deleteentry")) {
|
||||
if (itemKey.equals("deleteentry")) {
|
||||
// //出库单明细删除按钮
|
||||
// DynamicObjectCollection entryEntityCollection = this.getModel().getDataEntity(true).getDynamicObjectCollection("entryentity");//出库单分录
|
||||
// boolean hasFL001 = false;
|
||||
// for (DynamicObject entryEntity : entryEntityCollection) {
|
||||
// DynamicObject accountType = entryEntity.getDynamicObject("zcgj_accounttype");//科目属性
|
||||
// if (accountType != null && "FL001".equals(accountType.getString("number"))) {
|
||||
// //科目属性-为生成成本时
|
||||
// hasFL001 = true;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// BasedataEdit edit = this.getView().getControl("procbs");//工作分解结构
|
||||
// edit.setMustInput(hasFL001);// 设置必录
|
||||
// this.getView().updateView("entryentity");//刷新分录
|
||||
// }
|
||||
DynamicObjectCollection entryEntityCollection = this.getModel().getDataEntity(true).getDynamicObjectCollection("entryentity");//出库单分录
|
||||
for (int rowIndex = 0; rowIndex < entryEntityCollection.size(); rowIndex++) {
|
||||
DynamicObject dataEntity = entryEntityCollection.get(rowIndex);
|
||||
BigDecimal newValue = dataEntity.getBigDecimal("qty");//数量
|
||||
BigDecimal price = dataEntity.getBigDecimal("price");//单价(不含税)
|
||||
BigDecimal result = newValue.multiply(price).setScale(2, RoundingMode.HALF_UP);
|
||||
BigDecimal settleprice = dataEntity.getBigDecimal("settleprice");//结算单价
|
||||
this.getModel().setValue("amount", result, 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");//资源编码
|
||||
String modelnum1 = dataEntity.getString("modelnum");//规格型号
|
||||
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()));//即时库存-资源名称
|
||||
qFilters.and(new QFilter("modelnum", QCP.equals, modelnum1));//即时库存-规格型号
|
||||
DynamicObject ecma_matinventory = BusinessDataServiceHelper.loadSingle("ecma_matinventory", new QFilter[]{qFilters});//即时库存
|
||||
if (ecma_matinventory != null) {
|
||||
BigDecimal qty = ecma_matinventory.getBigDecimal("qty");//即时库存-可用数量
|
||||
BigDecimal price2 = ecma_matinventory.getBigDecimal("price");//即时库存-当前成本单价
|
||||
DynamicObjectCollection entryEntityCollection1 = this.getModel().getDataEntity(true).getDynamicObjectCollection("entryentity");//出库单分录
|
||||
BigDecimal totalQty = BigDecimal.ZERO;//修改行相同的资源编码数量
|
||||
BigDecimal totalAmount = BigDecimal.ZERO;//修改行不相同的资源编码数量
|
||||
for (int i = 0; i < entryEntityCollection1.size(); i++) {
|
||||
DynamicObject entryEntity = entryEntityCollection1.get(i);
|
||||
DynamicObject material1 = entryEntity.getDynamicObject("material");//出库单分录-资源编码
|
||||
String modelnum = entryEntity.getString("modelnum");//出库单分录-规格型号
|
||||
BigDecimal qty1 = entryEntity.getBigDecimal("qty");//出库单分录-数量
|
||||
BigDecimal amount = entryEntity.getBigDecimal("amount");//出库单分录-金额
|
||||
if (material1 == null) {
|
||||
continue;
|
||||
}
|
||||
if (!material.getPkValue().equals(material1.getPkValue())) {
|
||||
continue;
|
||||
}
|
||||
if (!Objects.equals(modelnum, modelnum1)) {
|
||||
continue;
|
||||
}
|
||||
totalQty = totalQty.add(qty1);
|
||||
if (rowIndex == i) {
|
||||
continue;
|
||||
}
|
||||
totalAmount = totalAmount.add(amount);
|
||||
}
|
||||
if (totalQty.compareTo(qty) == 0) {
|
||||
BigDecimal amount = ecma_matinventory.getBigDecimal("amount").subtract(totalAmount);
|
||||
this.getModel().setValue("amount", amount, rowIndex);//金额
|
||||
BigDecimal price1 = amount.divide(newValue, 2, RoundingMode.HALF_UP);
|
||||
this.getModel().setValue("price", price1, rowIndex);//单价(不含税)
|
||||
} else {
|
||||
this.getModel().setValue("price", price2, rowIndex);//单价(不含税)
|
||||
BigDecimal result1 = newValue.multiply(price2).setScale(2, RoundingMode.HALF_UP);
|
||||
this.getModel().setValue("amount", result1, rowIndex);//金额
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/* boolean hasFL001 = false;
|
||||
for (DynamicObject entryEntity : entryEntityCollection) {
|
||||
DynamicObject accountType = entryEntity.getDynamicObject("zcgj_accounttype");//科目属性
|
||||
if (accountType != null && "FL001".equals(accountType.getString("number"))) {
|
||||
//科目属性-为生成成本时
|
||||
hasFL001 = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
BasedataEdit edit = this.getView().getControl("procbs");//工作分解结构
|
||||
edit.setMustInput(hasFL001);// 设置必录
|
||||
this.getView().updateView("entryentity");//刷新分录*/
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Reference in New Issue