优化代码 计量分录清单数据带入结算分录
This commit is contained in:
parent
effc1455f0
commit
651726964e
|
@ -2,6 +2,7 @@ package zcgj.zcdev.zcdev.pr.plugin.form;
|
|||
|
||||
import kd.bos.dataentity.entity.DynamicObject;
|
||||
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
||||
import kd.bos.dataentity.metadata.IDataEntityType;
|
||||
import kd.bos.dataentity.resource.ResManager;
|
||||
import kd.bos.dataentity.utils.StringUtils;
|
||||
import kd.bos.entity.datamodel.events.ChangeData;
|
||||
|
@ -89,6 +90,7 @@ public class ContractEeasurementBillPlugin extends ContractMeasureBillEditPlugin
|
|||
String listModelId = (String) this.getModel().getValue("listmodelid", rowIndex);
|
||||
qFilters.add(new QFilter("listingmodel", "=", StringUtils.isNotBlank(listModelId) ? Long.parseLong(listModelId) : 0L));
|
||||
DynamicObject contract = (DynamicObject) this.getModel().getValue("contract");
|
||||
IDataEntityType dataEntityType = contract.getDataEntityType();
|
||||
if (contract != null) {
|
||||
qFilters.add(new QFilter("contractid", "=", contract.getLong("id")));
|
||||
}
|
||||
|
|
|
@ -0,0 +1,112 @@
|
|||
package zcgj.zcdev.zcdev.pr.plugin.form;
|
||||
|
||||
import kd.bos.context.RequestContext;
|
||||
import kd.bos.dataentity.entity.DynamicObject;
|
||||
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
||||
import kd.bos.dataentity.resource.ResManager;
|
||||
import kd.bos.form.CloseCallBack;
|
||||
import kd.bos.form.ShowFormHelper;
|
||||
import kd.bos.form.events.BeforeDoOperationEventArgs;
|
||||
import kd.bos.form.operate.FormOperate;
|
||||
import kd.bos.list.ListShowParameter;
|
||||
import kd.bos.orm.query.QFilter;
|
||||
import kd.bos.permission.api.HasPermOrgResult;
|
||||
import kd.ec.basedata.common.permission.ProjectPermissionHelper;
|
||||
import kd.ec.contract.common.enums.PayDirectionEnum;
|
||||
import kd.ec.contract.common.utils.ContractHelper;
|
||||
import kd.ec.contract.formplugin.PaymentApplyEditUI;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class PaymentApplyExtEditUI extends PaymentApplyEditUI {
|
||||
@Override
|
||||
public void beforeDoOperation(BeforeDoOperationEventArgs args) {
|
||||
FormOperate operate = (FormOperate)args.getSource();
|
||||
String key = operate.getOperateKey();
|
||||
if (!StringUtils.equals("submit", key) && !StringUtils.equals("save", key)) {
|
||||
if (StringUtils.equals(key, "newsubentry")) {
|
||||
this.beforeNewSubEntry(args);
|
||||
} else if (key.equals("deletesubentry")) {
|
||||
this.beforeDeleteSubEntry(args);
|
||||
} else if (StringUtils.equals(key, "newsubitementry")) {
|
||||
this.beforeNewSubItemEntry(args);
|
||||
} else if (key.equals("deletesubitementry")) {
|
||||
this.beforeDeleteSubItemEntry(args);
|
||||
} else if (key.equals("autofetch")) {
|
||||
this.beforeAutoFetch(args);
|
||||
} else if (key.equals("selectcontract")) {
|
||||
beforeSelectContract(args);
|
||||
} else if (key.equals("deleteentry")) {
|
||||
this.beforeDeleteEntry();
|
||||
} else if (key.equals("deleteitementry")) {
|
||||
this.beforeDeleteItemEntry();
|
||||
} else if (key.equals("itemautofetch")) {
|
||||
this.beforeItemAutoFetch(args);
|
||||
} else if (key.equals("refresh")) {
|
||||
this.beforeRefresh();
|
||||
} else if (key.equals("newitementry")) {
|
||||
this.beforeNewItemEntry(args);
|
||||
} else if (StringUtils.equals(key, "selectinvoice")) {
|
||||
this.showInvoiceImport(args);
|
||||
} else if (StringUtils.equals(key, "advancedetail")) {
|
||||
this.showAdvanceDetail();
|
||||
}
|
||||
} else {
|
||||
this.beforeSaveOrSubmit(args);
|
||||
}
|
||||
}
|
||||
|
||||
protected void beforeSelectContract(BeforeDoOperationEventArgs args) {
|
||||
DynamicObject period = (DynamicObject)this.getModel().getValue("period");
|
||||
if (period == null) {
|
||||
this.getView().showTipNotification(ResManager.loadKDString("请先选择期间。", "PaymentApplyEditUI_7", "ec-contract-formplugin", new Object[0]));
|
||||
args.setCancel(true);
|
||||
} else {
|
||||
DynamicObject project = (DynamicObject)this.getModel().getValue("project");
|
||||
ListShowParameter parameter = ShowFormHelper.createShowListForm("ec_out_contract_f7", true, 2);
|
||||
parameter.setShowUsed(true);
|
||||
parameter.setShowApproved(true);
|
||||
DynamicObject orgId = (DynamicObject)this.getModel().getValue("org");
|
||||
if (orgId != null) {
|
||||
boolean isMultiCurrency = this.getModel().getDataEntity().getBoolean("ismulticurrency");
|
||||
if (isMultiCurrency) {
|
||||
DynamicObject currency = this.getModel().getDataEntity().getDynamicObject("currency");
|
||||
if (currency != null) {
|
||||
Object currencyId = currency.getPkValue();
|
||||
QFilter currencyFilter = new QFilter("currency", "=", currencyId);
|
||||
parameter.getListFilterParameter().getQFilters().add(currencyFilter);
|
||||
}
|
||||
}
|
||||
QFilter orgFilter;
|
||||
if (project != null) {
|
||||
orgFilter = new QFilter("project", "=", project.getPkValue());
|
||||
} else {
|
||||
QFilter nullProjectFilter = new QFilter("project", "=", 0);
|
||||
HasPermOrgResult allPermOrg = ProjectPermissionHelper.getAllPermOrg(RequestContext.get().getCurrUserId(), "ecpf", "ec_paymentapply");
|
||||
if (!allPermOrg.hasAllOrgPerm()) {
|
||||
nullProjectFilter = nullProjectFilter.and(new QFilter("org", "in", allPermOrg.getHasPermOrgs()));
|
||||
}
|
||||
|
||||
orgFilter = nullProjectFilter;
|
||||
}
|
||||
|
||||
parameter.getListFilterParameter().getQFilters().add(orgFilter);
|
||||
DynamicObjectCollection entries = this.getModel().getEntryEntity("entryentity");
|
||||
Set<Long> selectContractIds = new HashSet(entries.size());
|
||||
entries.forEach((entry) -> {
|
||||
selectContractIds.add(entry.getDynamicObject("contract").getLong("id"));
|
||||
});
|
||||
// parameter.getListFilterParameter().getQFilters().add(new QFilter("id", "not in", selectContractIds));
|
||||
ContractHelper.getContractByStatus("ec_paymentapply", parameter, PayDirectionEnum.OUT.getValue());
|
||||
CloseCallBack callBack = new CloseCallBack(this, "ec_out_contract");
|
||||
parameter.setCloseCallBack(callBack);
|
||||
this.getView().showForm(parameter);
|
||||
} else {
|
||||
this.getView().showTipNotification(ResManager.loadKDString("所属组织为空,无法选择合同", "PaymentApplyEditUI_8", "ec-contract-formplugin", new Object[0]));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,11 +1,22 @@
|
|||
package zcgj.zcdev.zcdev.pr.plugin.operate;
|
||||
|
||||
import kd.bos.dataentity.entity.DynamicObject;
|
||||
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
||||
import kd.bos.dataentity.metadata.dynamicobject.DynamicObjectType;
|
||||
import kd.bos.entity.operate.result.OperationResult;
|
||||
import kd.bos.entity.plugin.AddValidatorsEventArgs;
|
||||
import kd.bos.entity.validate.AbstractValidator;
|
||||
import kd.bos.servicehelper.QueryServiceHelper;
|
||||
import kd.bos.servicehelper.operation.SaveServiceHelper;
|
||||
import kd.ec.basedata.common.utils.EcDynamicObjectUtil;
|
||||
import kd.bos.orm.query.QFilter;
|
||||
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
||||
import kd.ec.contract.opplugin.OutContractSettleOp;
|
||||
import kd.ec.contract.opplugin.validator.OutContractSettleValidator;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class OutContractSettlementOp extends OutContractSettleOp {
|
||||
|
||||
|
@ -18,5 +29,13 @@ public class OutContractSettlementOp extends OutContractSettleOp {
|
|||
|
||||
// 添加定制二开的校验器(位置放第一位,优先执行)
|
||||
validators.add(0, new OutContractSettlementValidator());
|
||||
|
||||
//提交时做合同清单操作
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializeOperationResult(OperationResult result) {
|
||||
super.initializeOperationResult(result);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,16 +5,88 @@ import kd.bos.dataentity.entity.DynamicObjectCollection;
|
|||
import kd.bos.dataentity.resource.ResManager;
|
||||
import kd.bos.dataentity.utils.StringUtils;
|
||||
import kd.bos.entity.ExtendedDataEntity;
|
||||
import kd.bos.entity.operate.result.OperationResult;
|
||||
import kd.bos.orm.query.QFilter;
|
||||
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
||||
import kd.bos.servicehelper.QueryServiceHelper;
|
||||
import kd.bos.servicehelper.operation.SaveServiceHelper;
|
||||
import kd.ec.contract.opplugin.validator.OutContractSettleValidator;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class OutContractSettlementValidator extends OutContractSettleValidator {
|
||||
@Override
|
||||
protected boolean validateSettleAmount(ExtendedDataEntity dataEntity) {
|
||||
{
|
||||
DynamicObject dataEntity1 = dataEntity.getDataEntity();
|
||||
DynamicObjectCollection listmodelentrys = dataEntity1.getDynamicObjectCollection("listmodelentry");//分录
|
||||
for (DynamicObject payitemdetailentry : dataEntity1.getDynamicObjectCollection("payitemdetailentry")) {
|
||||
long referbillid = payitemdetailentry.getLong("referbillid");
|
||||
QFilter f1 = new QFilter("id", "=", referbillid);
|
||||
DynamicObject outcontractmeasure = BusinessDataServiceHelper.loadSingle("ec_outcontractmeasure", new QFilter[]{f1});
|
||||
DynamicObjectCollection listmodelentry = outcontractmeasure.getDynamicObjectCollection("listmodelentry");
|
||||
//判断是否有含有计量单id 若有跳过 避免多次新增
|
||||
Set<String> set = new HashSet();
|
||||
// QFilter f2 = new QFilter("id", "!=", "0");
|
||||
DynamicObjectCollection query = QueryServiceHelper.query(dataEntity1.getDynamicObjectType().getName(), "listmodelentry.zcgj_jldenrtyid", null);
|
||||
// DynamicObject[] jldenrtyids = BusinessDataServiceHelper.load(listmodelentrys.getDynamicObjectType().getName(),"zcgj_jldenrtyid", new QFilter[]{f2});
|
||||
for (DynamicObject object : query) {
|
||||
String id = object.getString("listmodelentry.zcgj_jldenrtyid");
|
||||
if (id != null) {
|
||||
set.add(id);
|
||||
}
|
||||
}
|
||||
for (DynamicObject listmodelEntry : listmodelentry) {
|
||||
String id = listmodelEntry.getString("id");
|
||||
if (set.contains(id)) {
|
||||
continue;
|
||||
}
|
||||
DynamicObject addNew = listmodelentrys.addNew();
|
||||
addNew.set("modelname", listmodelEntry.getString("modelname"));//清单模板名称
|
||||
addNew.set("cmptype", listmodelEntry.getString("cmptype"));//文本
|
||||
addNew.set("totalamount", listmodelEntry.getBigDecimal("totalamount"));//税额
|
||||
addNew.set("totaltax", listmodelEntry.getBigDecimal("totaltax"));//税额
|
||||
addNew.set("totaloftaxamount", listmodelEntry.getBigDecimal("totaloftaxamount"));//价税合计
|
||||
addNew.set("listmodelid", listmodelEntry.getLong(("listmodelid")));//清单模板id
|
||||
addNew.set("zcgj_jldenrtyid", id);//计量单分录id
|
||||
DynamicObjectCollection listEntry = addNew.getDynamicObjectCollection("listentry");//结算分录
|
||||
DynamicObjectCollection measureEntry = listmodelEntry.getDynamicObjectCollection("listentry");//计量分录
|
||||
for (DynamicObject dynamicObject : measureEntry) {
|
||||
DynamicObject object = listEntry.addNew();
|
||||
object.set("listing", dynamicObject.getDynamicObject("listing"));//清单编码
|
||||
object.set("listingname", dynamicObject.getString("listingname"));//清单名称
|
||||
object.set("materiel", dynamicObject.getDynamicObject("materiel"));//物料编码
|
||||
object.set("resourceitem", dynamicObject.getDynamicObject("listing"));//资源编码
|
||||
object.set("resname", dynamicObject.getString("resname"));//资源名称
|
||||
object.set("boqnumber", dynamicObject.getDynamicObject("boqnumber"));//工程量清单编码
|
||||
object.set("contlistnumber", dynamicObject.getDynamicObject("contlistnumber"));//
|
||||
object.set("measureunit", dynamicObject.getDynamicObject("measureunit"));//计量单位
|
||||
object.set("totalqty", dynamicObject.getBigDecimal("totalqty"));//总数量
|
||||
object.set("entrytaxrate", dynamicObject.getBigDecimal("entrytaxrate"));//税率(%)
|
||||
object.set("curtaxprice", dynamicObject.getBigDecimal("curtaxprice"));//当前含税单价
|
||||
object.set("currentprice", dynamicObject.getBigDecimal("currentprice"));//当前单价
|
||||
object.set("currentamt", dynamicObject.getBigDecimal("currentamt"));//当前金额
|
||||
object.set("currenttaxamt", dynamicObject.getBigDecimal("currenttaxamt"));//当前税额
|
||||
object.set("currentoftax", dynamicObject.getBigDecimal("currentoftax"));//当前价税合计
|
||||
object.set("preqty", dynamicObject.getBigDecimal("preqty"));//期初累计计量数量
|
||||
object.set("preamout", dynamicObject.getBigDecimal("preamout"));//期初累计计量金额
|
||||
object.set("thisqty", dynamicObject.getBigDecimal("thisqty"));//本期计量数量
|
||||
object.set("thisamount", dynamicObject.getBigDecimal("thisamount"));//本期计量不含税金额
|
||||
object.set("thistax", dynamicObject.getBigDecimal("thistax"));//本期税额
|
||||
object.set("thisoftaxmount", dynamicObject.getBigDecimal("thisoftaxmount"));//本期计量含税金额
|
||||
object.set("lstqty", dynamicObject.getBigDecimal("lstqty"));//期末累计计量数量
|
||||
object.set("lstamount", dynamicObject.getBigDecimal("lstamount"));//期末累计计量不含税金额
|
||||
object.set("listca", dynamicObject.getDynamicObject("listca"));//成本科目
|
||||
object.set("listcbs", dynamicObject.getDynamicObject("listcbs"));//成本分解结构
|
||||
object.set("listboq", dynamicObject.getDynamicObject("listboq"));//工程量清单
|
||||
object.set("desc", dynamicObject.getString("desc"));//说明
|
||||
}
|
||||
}
|
||||
}
|
||||
OperationResult saveOperationResult = SaveServiceHelper.saveOperate(dataEntity1.getDataEntityType().getName(), new DynamicObject[]{dataEntity1}, null);//项目实体
|
||||
|
||||
BigDecimal settleOfTaxAmount = dataEntity.getDataEntity().getBigDecimal("settleoftaxamount");
|
||||
DynamicObject contractTemp = dataEntity.getDataEntity().getDynamicObject("contract");
|
||||
|
||||
|
@ -53,5 +125,7 @@ public class OutContractSettlementValidator extends OutContractSettleValidator {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// for (DynamicObject dataEntity : e.getDataEntities()) {
|
||||
}
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -16,12 +16,10 @@ public class PaymentApplyFundExtOp extends PaymentApplyFundOp {
|
|||
super.onAddValidators(e);
|
||||
List<AbstractValidator> validators = e.getValidators();
|
||||
// 删除标品校验器
|
||||
validators.removeIf(validator -> validator instanceof PaymentMaxAmountValidator);
|
||||
// validators.removeIf(validator -> validator instanceof PaymentMaxAmountValidator);
|
||||
validators.removeIf(validator -> validator instanceof PaymentTypeValidator);
|
||||
|
||||
|
||||
// 添加定制二开的校验器(位置放第一位,优先执行)
|
||||
// validators.add(0, new ContractMeasurementValidator());
|
||||
validators.add(0, new PaymentMaxAmountExtValidator());
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
package zcgj.zcdev.zcdev.pr.plugin.operate;
|
||||
|
||||
import kd.bos.dataentity.entity.DynamicObject;
|
||||
import kd.bos.dataentity.resource.ResManager;
|
||||
import kd.bos.dataentity.utils.StringUtils;
|
||||
import kd.bos.entity.ExtendedDataEntity;
|
||||
import kd.ec.basedata.common.utils.CurrencyFormatUtil;
|
||||
import kd.ec.contract.opplugin.fund.validator.PaymentMaxAmountValidator;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class PaymentMaxAmountExtValidator extends PaymentMaxAmountValidator {
|
||||
|
||||
@Override
|
||||
protected void maxShouldPayAmountValidate(Map<Long, BigDecimal> contractTypeShouldPayAmountMap, Map<Long, BigDecimal> shouldPayAmountMap, Map<Long, Set<String>> appliedBillMap, ExtendedDataEntity dataEntity, int i, DynamicObject entry, DynamicObject contract) {
|
||||
|
||||
long contractId = contract.getLong("id");
|
||||
BigDecimal maxShouldPayAmount = this.calculateMaxShouldPayAmount(contract);
|
||||
DynamicObject contCurrency = contract.getDynamicObject("currency");
|
||||
if (contCurrency != null) {
|
||||
maxShouldPayAmount = maxShouldPayAmount.setScale(contCurrency.getInt("amtprecision"), 4);
|
||||
}
|
||||
|
||||
BigDecimal curMaxShouldPayAmount = entry.getBigDecimal("maxshouldpayamt");
|
||||
BigDecimal curShouldPayAmount = entry.getBigDecimal("applyoftaxamount");
|
||||
BigDecimal submitShouldPayAmount = (BigDecimal)shouldPayAmountMap.getOrDefault(contractId, BigDecimal.ZERO);
|
||||
BigDecimal totalShouldPayAmount = (BigDecimal)contractTypeShouldPayAmountMap.getOrDefault(contractId, BigDecimal.ZERO);
|
||||
if (totalShouldPayAmount.add(submitShouldPayAmount).compareTo(maxShouldPayAmount) > 0) {
|
||||
if (appliedBillMap.containsKey(contractId)) {
|
||||
// Set<String> billNumbers = (Set)appliedBillMap.get(contractId);
|
||||
// this.addErrorMessage(dataEntity, String.format(ResManager.loadKDString("合同付款信息:第%1$s行因受流程中单据(单据号:%2$s)影响,继续提交将超过应付金额上限。在途金额:%3$s。", "PaymentMaxAmountValidator_6", "ec-contract-opplugin", new Object[0]), i + 1, StringUtils.join(billNumbers.toArray(new String[0]), ","), CurrencyFormatUtil.getAfterFormatString(contCurrency, submitShouldPayAmount.add(totalShouldPayAmount.subtract(curShouldPayAmount)))));
|
||||
} else if (maxShouldPayAmount.compareTo(curMaxShouldPayAmount) != 0) {
|
||||
this.addErrorMessage(dataEntity, String.format(ResManager.loadKDString("合同付款信息:第%s行因暂存期间存在其他单据提交审核,导致应付金额上限发生变化,本单数据未刷新,继续提交将超过应付金额上限。", "PaymentMaxAmountValidator_1", "ec-contract-opplugin", new Object[0]), i + 1));
|
||||
} else {
|
||||
this.addErrorMessage(dataEntity, String.format(ResManager.loadKDString("合同付款信息:第%s行本次应付金额不允许超应付金额上限,请确认。", "PaymentMaxAmountValidator_2", "ec-contract-opplugin", new Object[0]), i + 1));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue