入库单添加费用汇总分录新增赋值逻辑
This commit is contained in:
parent
ee7f70ad6f
commit
57071d39c5
|
@ -1,22 +1,14 @@
|
|||
package zcgj.zcdev.zcdev.pr.plugin.form;
|
||||
|
||||
import kd.bos.algo.DataSet;
|
||||
import kd.bos.algo.JoinDataSet;
|
||||
import kd.bos.algo.JoinType;
|
||||
import kd.bos.algo.Row;
|
||||
import kd.bos.bill.AbstractBillPlugIn;
|
||||
import kd.bos.context.RequestContext;
|
||||
import kd.bos.dataentity.entity.DynamicObject;
|
||||
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
||||
import kd.bos.dataentity.metadata.dynamicobject.DynamicObjectType;
|
||||
import kd.bos.dataentity.resource.ResManager;
|
||||
import kd.bos.dataentity.utils.StringUtils;
|
||||
import kd.bos.entity.EntityMetadataCache;
|
||||
import kd.bos.entity.datamodel.ListSelectedRowCollection;
|
||||
import kd.bos.entity.datamodel.events.ChangeData;
|
||||
import kd.bos.entity.datamodel.events.PropertyChangedArgs;
|
||||
import kd.bos.form.*;
|
||||
import kd.bos.form.control.EntryGrid;
|
||||
import kd.bos.form.events.AfterDoOperationEventArgs;
|
||||
import kd.bos.form.control.events.ItemClickEvent;
|
||||
import kd.bos.form.events.BeforeDoOperationEventArgs;
|
||||
import kd.bos.form.events.ClosedCallBackEvent;
|
||||
import kd.bos.form.field.BasedataEdit;
|
||||
|
@ -34,7 +26,6 @@ import kd.sdk.plugin.Plugin;
|
|||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 入库单表单插件
|
||||
|
@ -44,6 +35,7 @@ import java.util.stream.Collectors;
|
|||
* 4:申请人部门根据物资申请人过滤部门
|
||||
* 5:申请人部门赋值逻辑
|
||||
* 6:合同编码字段赋值
|
||||
* 7:费用汇总分录新增赋值逻辑
|
||||
*/
|
||||
public class MaterialInbPurchaseApplyPlugin extends AbstractBillPlugIn implements Plugin, BeforeF7SelectListener {
|
||||
@Override
|
||||
|
@ -53,6 +45,7 @@ public class MaterialInbPurchaseApplyPlugin extends AbstractBillPlugIn implement
|
|||
purchaseApply.addBeforeF7SelectListener(this);
|
||||
BasedataEdit zcgj_applidepart = getView().getControl("zcgj_applidepart");//申请人部门
|
||||
zcgj_applidepart.addBeforeF7SelectListener(this);
|
||||
this.addItemClickListeners("advcontoolbarap");//入库单明细工具栏
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -63,6 +56,16 @@ public class MaterialInbPurchaseApplyPlugin extends AbstractBillPlugIn implement
|
|||
this.getModel().setValue("zcgj_applidepart", mainOrgID);//申请人部门
|
||||
}
|
||||
|
||||
@Override
|
||||
public void itemClick(ItemClickEvent evt) {
|
||||
super.itemClick(evt);
|
||||
String itemKey = evt.getItemKey();
|
||||
if (itemKey.equals("delentry")) {
|
||||
//入库单明细-删行
|
||||
setNewExpenseSummary();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void propertyChanged(PropertyChangedArgs e) {
|
||||
super.propertyChanged(e);
|
||||
|
@ -74,20 +77,6 @@ public class MaterialInbPurchaseApplyPlugin extends AbstractBillPlugIn implement
|
|||
Object newValue = changeData.getNewValue();//新值
|
||||
Object oldValue = changeData.getOldValue();//旧值
|
||||
if (newValue == null || !newValue.equals(oldValue)) {
|
||||
// // 消息模板#{x}为超链接占位符,格式如“保存成功,#{0},单据详情,#{1}”
|
||||
// String tempMsg = "更改采购申请单将自动清单入库单明细,您确定更改吗?";
|
||||
// List<MessageBoxLink> msglinks = new ArrayList<MessageBoxLink>();
|
||||
// // 消息框按钮类型
|
||||
// MessageBoxOptions options = MessageBoxOptions.OKCancel;
|
||||
// // 确认提示类型
|
||||
// ConfirmTypes confirmTypes = ConfirmTypes.Default;
|
||||
// // 确认框回调
|
||||
// ConfirmCallBackListener callBack = new ConfirmCallBackListener("CALLBACKID_DEMO2", this);
|
||||
// // 按钮名称
|
||||
// Map<Integer, String> btnNameMaps = new HashMap<Integer, String>();
|
||||
// btnNameMaps.put(2, "按钮名称2");
|
||||
// btnNameMaps.put(6, "按钮名称6");
|
||||
// this.getView().showConfirm(tempMsg, msglinks, options, confirmTypes, callBack, btnNameMaps);
|
||||
DynamicObjectCollection entryCollection = this.getModel().getDataEntity(true).getDynamicObjectCollection("entryentity");//入库单分录
|
||||
entryCollection.clear();
|
||||
this.getView().updateView("entryentity");//刷新分录
|
||||
|
@ -137,6 +126,16 @@ public class MaterialInbPurchaseApplyPlugin extends AbstractBillPlugIn implement
|
|||
DynamicObject zcgj_reqperson = (DynamicObject) newValue;//物资申请人
|
||||
long mainOrgID = UserServiceHelper.getUserMainOrgId((Long) zcgj_reqperson.getPkValue());//获取用户默认部门id
|
||||
this.getModel().setValue("zcgj_applidepart", mainOrgID);//申请人部门
|
||||
} else if ("totaloftaxamount".equals(key) || "taxamount".equals(key)) {
|
||||
//入库含税总金额,税额
|
||||
if ("taxamount".equals(key)) {
|
||||
//税额
|
||||
Boolean adjustamount = (Boolean) this.getModel().getValue("adjustamount");//微调金额
|
||||
if (!adjustamount) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
setNewExpenseSummary();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -279,4 +278,110 @@ public class MaterialInbPurchaseApplyPlugin extends AbstractBillPlugIn implement
|
|||
this.getView().showForm(formShowParameter);
|
||||
}
|
||||
}
|
||||
|
||||
private void setNewExpenseSummary() {
|
||||
DynamicObjectCollection entryEntityCollection = this.getModel().getDataEntity(true).getDynamicObjectCollection("entryentity");//入库单分录
|
||||
DynamicObjectCollection expenseSummaryCollection = this.getModel().getDataEntity(true).getDynamicObjectCollection("zcgj_expensesummary");//费用汇总分录
|
||||
expenseSummaryCollection.clear();
|
||||
DynamicObjectType expenseSummaryType = expenseSummaryCollection.getDynamicObjectType();
|
||||
for (DynamicObject entryEntity : entryEntityCollection) {
|
||||
DynamicObject newExpenseSummaryEntity = new DynamicObject(expenseSummaryType);
|
||||
newExpenseSummaryEntity.set("zcgj_pa_amount", entryEntity.get("oftaxamount"));//价税合计-含税金额
|
||||
newExpenseSummaryEntity.set("zcgj_amountnotax", entryEntity.get("notaxamount"));//不含税金额-金额
|
||||
DynamicObject entryTaxRate = entryEntity.getDynamicObject("entrytaxrate");//税率名称
|
||||
if (entryTaxRate != null) {
|
||||
newExpenseSummaryEntity.set("zcgj_rateval", entryTaxRate.get("taxrate"));//税率(%)-税率名称(值
|
||||
}
|
||||
newExpenseSummaryEntity.set("zcgj_taxamt", entryEntity.get("taxamount"));//税额-税额
|
||||
|
||||
DynamicObject expenseItem = null;
|
||||
DynamicObject material = entryEntity.getDynamicObject("material");//入库单分录-资源编码
|
||||
if (material != null) {
|
||||
DynamicObject resource = material.getDynamicObject("resource");//入库单分录-资源编码-清单分类
|
||||
if (resource != null) {
|
||||
String resourceNumber = resource.getString("number");//资源编码-清单分类-编码
|
||||
DynamicObject ecbd_resource = BusinessDataServiceHelper.loadSingle("ecbd_resource",
|
||||
"id,zcgj_expenseitem", new QFilter[]{new QFilter("number", QCP.equals, resourceNumber)});//清单分类
|
||||
expenseItem = ecbd_resource.getDynamicObject("zcgj_expenseitem");//费用项目
|
||||
}
|
||||
}
|
||||
newExpenseSummaryEntity.set("zcgj_expenseitem", expenseItem);//费用项目-对应费用项目
|
||||
|
||||
expenseSummaryCollection.add(newExpenseSummaryEntity);
|
||||
}
|
||||
mergeExpenseSummaryEntriesByExpenseItemAndRate(expenseSummaryCollection);
|
||||
this.getView().updateView("zcgj_expensesummary");//刷新分录
|
||||
}
|
||||
|
||||
/**
|
||||
* 按费用项目和税率组合合并费用汇总条目
|
||||
*
|
||||
* @param expenseSummaryCollection 费用汇总集合
|
||||
*/
|
||||
private void mergeExpenseSummaryEntriesByExpenseItemAndRate(DynamicObjectCollection expenseSummaryCollection) {
|
||||
// 使用Map来存储已存在的费用项目+税率组合,避免嵌套循环
|
||||
Map<String, DynamicObject> expenseItemRateMap = new HashMap<>();
|
||||
|
||||
for (int i = 0; i < expenseSummaryCollection.size(); i++) {
|
||||
DynamicObject currentEntry = expenseSummaryCollection.get(i);
|
||||
Object currentExpenseItem = currentEntry.get("zcgj_expenseitem"); // 费用项目
|
||||
Object currentRate = currentEntry.get("zcgj_rateval"); // 税率
|
||||
|
||||
// 创建唯一键值:费用项目ID + 税率值
|
||||
String key = (currentExpenseItem != null ? currentExpenseItem.toString() : "null") +
|
||||
"_" +
|
||||
(currentRate != null ? currentRate.toString() : "null");
|
||||
|
||||
if (expenseItemRateMap.containsKey(key)) {
|
||||
// 如果已存在相同组合,则合并数值
|
||||
DynamicObject existingEntry = expenseItemRateMap.get(key);
|
||||
|
||||
// 合并价税合计
|
||||
BigDecimal currentAmount = toBigDecimal(existingEntry.get("zcgj_pa_amount"));
|
||||
BigDecimal nextAmount = toBigDecimal(currentEntry.get("zcgj_pa_amount"));
|
||||
existingEntry.set("zcgj_pa_amount", currentAmount.add(nextAmount));
|
||||
|
||||
// 合并不含税金额
|
||||
BigDecimal currentAmountNoTax = toBigDecimal(existingEntry.get("zcgj_amountnotax"));
|
||||
BigDecimal nextAmountNoTax = toBigDecimal(currentEntry.get("zcgj_amountnotax"));
|
||||
existingEntry.set("zcgj_amountnotax", currentAmountNoTax.add(nextAmountNoTax));
|
||||
|
||||
// 合并税额
|
||||
BigDecimal currentTaxAmt = toBigDecimal(existingEntry.get("zcgj_taxamt"));
|
||||
BigDecimal nextTaxAmt = toBigDecimal(currentEntry.get("zcgj_taxamt"));
|
||||
existingEntry.set("zcgj_taxamt", currentTaxAmt.add(nextTaxAmt));
|
||||
|
||||
// 移除当前条目
|
||||
expenseSummaryCollection.remove(i);
|
||||
i--; // 调整索引
|
||||
} else {
|
||||
// 如果不存在相同组合,则添加到Map中
|
||||
expenseItemRateMap.put(key, currentEntry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将对象转换为BigDecimal类型
|
||||
*
|
||||
* @param obj 待转换对象
|
||||
* @return BigDecimal值
|
||||
*/
|
||||
private BigDecimal toBigDecimal(Object obj) {
|
||||
if (obj == null) {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
if (obj instanceof BigDecimal) {
|
||||
return (BigDecimal) obj;
|
||||
} else if (obj instanceof Number) {
|
||||
return new BigDecimal(obj.toString());
|
||||
} else {
|
||||
try {
|
||||
return new BigDecimal(obj.toString());
|
||||
} catch (NumberFormatException e) {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue