dobe_comic8/main/java/shkd/repc/rebm/opplugin/WriteBackAdjustAmountOpPlug...

98 lines
6.3 KiB
Java
Raw Normal View History

package shkd.repc.rebm.opplugin;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
import kd.bos.entity.plugin.args.AfterOperationArgs;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.operation.SaveServiceHelper;
import kd.sdk.plugin.Plugin;
import java.math.BigDecimal;
/**
* 单据操作插件
*/
public class WriteBackAdjustAmountOpPlugin extends AbstractOperationServicePlugIn implements Plugin {
/*
* 目标成本调整-审核/反审核时触发根据合约规划回传调整后金额
* */
@Override
public void afterExecuteOperationTransaction(AfterOperationArgs e) {
super.afterExecuteOperationTransaction(e);
String operationKey = e.getOperationKey();
if ("audit".equals(operationKey) || "test".equals(operationKey)) {
DynamicObject[] dataEntities = e.getDataEntities();
for (DynamicObject dataEntity : dataEntities) {
dataEntity = BusinessDataServiceHelper.loadSingle(dataEntity.getPkValue(), "recos_aimadjust");
DynamicObject decision = dataEntity.getDynamicObject("qeug_decision");//定标
DynamicObjectCollection conPlanAdjustEntries = dataEntity.getDynamicObjectCollection("conplanadjustentry");// 未签约调整分录
if (decision != null) {
DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle(decision.getPkValue(), "rebm_decision");
int sectionSeq = dataEntity.getInt("qeug_section_seq");
DynamicObjectCollection bottomSections = dynamicObject.getDynamicObjectCollection("bottomsection");
if (bottomSections != null) {
for (DynamicObject bottomSection : bottomSections) {
int bottomSeq = bottomSection.getInt("seq");
if (sectionSeq == bottomSeq) {
DynamicObjectCollection bottomEntries = bottomSection.getDynamicObjectCollection("bottomentry");// 采购明细
if (bottomEntries != null) {
String billNo = dynamicObject.getString("billno");
String changeSection = dynamicObject.getString("qeug_change_section");// 参与变更的标段
QFilter billNoQF = new QFilter("billno", QCP.equals, billNo);
DynamicObject project = BusinessDataServiceHelper.loadSingle("rebm_project", billNoQF.toArray());// 标前预备会
if (project != null) {
if (!changeSection.contains(String.valueOf(sectionSeq)))
changeSection = changeSection + ";" + sectionSeq;
DynamicObjectCollection bidSections = project.getDynamicObjectCollection("bidsection");// 标段
DynamicObject bidSection = bidSections.get(sectionSeq - 1);
DynamicObjectCollection projectEntries = bidSection.getDynamicObjectCollection("projectentry");// 采购明细
for (int i = 0; i < bottomEntries.size(); i++) {
DynamicObject bottomEntry = bottomEntries.get(i);
BigDecimal planAmount = bottomEntry.getBigDecimal("planamount");
if (planAmount.equals(new BigDecimal("0.0000000000"))) continue;
DynamicObject projectEntry = projectEntries.get(i);
DynamicObject cqprogcon = projectEntry.getDynamicObject("cqprogcon");// 合约规划
if (conPlanAdjustEntries != null) {
for (DynamicObject conPlanAdjustEntry : conPlanAdjustEntries) {
DynamicObject conplan = conPlanAdjustEntry.getDynamicObject("cpentry_conplan");
if (conplan.getLong("id") == cqprogcon.getLong("id")) {
BigDecimal adjustSumAmt = conPlanAdjustEntry.getBigDecimal("cpentry_adjustsumamt");// 调整后金额
bottomEntry.set("qeug_planamount", bottomEntry.getBigDecimal("planamount"));
bottomEntry.set("qeug_botcontrolamount", bottomEntry.getBigDecimal("botcontrolamount"));
bottomEntry.set("planamount", adjustSumAmt);
bottomEntry.set("botcontrolamount", adjustSumAmt);
bottomEntry.set("botctrlamtexceptvat", adjustSumAmt);
bottomEntry.set("nottaxplanamount", adjustSumAmt);
BigDecimal controlamount = dynamicObject.getBigDecimal("controlamount").add(adjustSumAmt.subtract(bottomEntry.getBigDecimal("botcontrolamount")));
dynamicObject.set("controlamount", controlamount);
dynamicObject.set("exctaxcontrolamount", controlamount);
}
}
}
}
dynamicObject.set("qeug_change_section", changeSection);
dynamicObject.set("qeug_conplan_adjust", String.valueOf(dataEntity.getPkValue()));
SaveServiceHelper.update(dynamicObject);
}
}
}
}
}
}
}
}
}
}