Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
zhangzhiguo 2025-07-15 16:56:40 +08:00
commit ebfdff5367
1 changed files with 199 additions and 0 deletions

View File

@ -0,0 +1,199 @@
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//
package zcgj.zcdev.zcdev.pr.plugin.form;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.dataentity.utils.StringUtils;
import kd.bos.entity.plugin.PreparePropertysEventArgs;
import kd.bos.entity.plugin.args.BeforeOperationArgs;
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.ec.contract.common.enums.SourceTypeEnum;
import kd.ec.contract.common.utils.EcConstant;
import kd.ec.contract.common.utils.EcNumberHelper;
import kd.ec.contract.opplugin.AbstractReverseWritingContractOp;
//二开系统插件-付款申请单审核与反审核操作插件:修改累计收票金额逻辑
public class PayApplyOpExt extends AbstractReverseWritingContractOp {
private static String selector = (String)Stream.of("totalapplyoftaxamount", "totalapplyamount", "taxrate", "totalinvoiceamount", "totalinvoiceoftaxamount", "currency", "org").collect(Collectors.joining(","));
public PayApplyOpExt() {
}
public void onPreparePropertys(PreparePropertysEventArgs e) {
List<String> fields = e.getFieldKeys();
fields.add("entryentity.applyoftaxamount");
fields.add("entryentity.contract");
fields.add("subentryentity.invoice");
fields.add("sourcetype");
fields.add("entryentity.applyinvamt");
fields.add("entryentity.applyinvtax");
}
public void beforeExecuteOperationTransaction(BeforeOperationArgs e) {
super.beforeExecuteOperationTransaction(e);
String key = e.getOperationKey();
if ("delete".equals(key)) {
DynamicObject[] bills = e.getDataEntities();
DynamicObject[] var4 = bills;
int var5 = bills.length;
for(int var6 = 0; var6 < var5; ++var6) {
DynamicObject bill = var4[var6];
DynamicObjectCollection entryCol = bill.getDynamicObjectCollection("entryentity");
if (entryCol.size() != 0) {
Iterator var9 = entryCol.iterator();
while(var9.hasNext()) {
DynamicObject entryObj = (DynamicObject)var9.next();
DynamicObjectCollection subEntryCol = entryObj.getDynamicObjectCollection("subentryentity");
if (subEntryCol.size() > 0) {
this.delSubEntry(subEntryCol);
}
}
}
}
}
}
private void delSubEntry(DynamicObjectCollection subEntryCol) {
DynamicObject[] invArr = new DynamicObject[subEntryCol.size()];
for(int i = 0; i < subEntryCol.size(); ++i) {
DynamicObject subEntry = (DynamicObject)subEntryCol.get(i);
DynamicObject invoice = subEntry.getDynamicObject("invoice");
invoice = BusinessDataServiceHelper.loadSingle(invoice.getPkValue(), "ec_in_invoice", "isinvoiceclaim,isclaimed,contract,project,connecttype");
if (!invoice.getBoolean("isinvoiceclaim")) {
invoice.set("isclaimed", false);
invoice.set("project", (Object)null);
invoice.set("contract", (Object)null);
invoice.set("connecttype", "");
}
invArr[i] = invoice;
}
SaveServiceHelper.save(invArr);
}
public void reverseWritingToContract(String operationKey, DynamicObject source) {
if (source.getString("sourcetype").equals(SourceTypeEnum.CONTRACT.value)) {//合同收款
DynamicObject incomeApply = BusinessDataServiceHelper.loadSingle(source.getPkValue(), "ec_paymentapply");//付款申请单
DynamicObjectCollection entryEntity = incomeApply.getDynamicObjectCollection("entryentity");//付款信息分录
if (entryEntity.size() > 0) {
List<DynamicObject> contractList = new ArrayList();
Map<Long, DynamicObject> contractMap = new HashMap();
Iterator var7 = entryEntity.iterator();
while(true) {
DynamicObject cont;
BigDecimal thisApplyOfTaxAmount;
do {
if (!var7.hasNext()) {
var7 = contractMap.keySet().iterator();
while(var7.hasNext()) {
Long contractId = (Long)var7.next();
contractList.add(contractMap.get(contractId));
}
SaveServiceHelper.save((DynamicObject[])contractList.toArray(new DynamicObject[0]));//保存支出合同
return;
}
cont = (DynamicObject)var7.next();
thisApplyOfTaxAmount = cont.getBigDecimal("applyoftaxamount");//本次应付金额
} while(null == cont.getDynamicObject("contract"));//合同名称
Long contractId = cont.getDynamicObject("contract").getLong("id");//合同名称id
DynamicObject contract;
if (contractMap.containsKey(contractId)) {
contract = (DynamicObject)contractMap.get(contractId);
} else {
contract = BusinessDataServiceHelper.loadSingle(contractId, "ec_out_contract", selector);//支出合同
contractMap.put(contractId, contract);
}
BigDecimal totalInvoiceAmount = BigDecimal.ZERO;
QFilter[] contractFilter = new QFilter[]{new QFilter("zcgj_contract.id", QCP.equals, contractId).and("billstatus", QCP.equals, "C")}; // 合同筛选条件
DynamicObject[] financeConfirmObjs = BusinessDataServiceHelper.load("zcgj_ec_out_finaceconfirm", "id,billstatus,zcgj_entryentity,zcgj_entryentity.zcgj_invoiceamount", contractFilter); // 支出财务确认
for (int i = 0; i < financeConfirmObjs.length; i++) {
DynamicObject financeConfirmObj = financeConfirmObjs[i];
DynamicObjectCollection invoiceEntryList = financeConfirmObj.getDynamicObjectCollection("zcgj_entryentity"); // 支出财务确认-合同进项发票信息
for (int j = 0; j < invoiceEntryList.size(); j++) {
DynamicObject invoiceEntry = invoiceEntryList.get(j);
BigDecimal invoiceAmount = invoiceEntry.getBigDecimal("zcgj_invoiceamount"); // 发票金额
totalInvoiceAmount = totalInvoiceAmount.add(invoiceAmount);
}
}
BigDecimal totalApplyOfTaxAmount = contract.getBigDecimal("totalapplyoftaxamount");//支出合同-累计应付含税金额
BigDecimal totalApplyAmount = contract.getBigDecimal("totalapplyamount");//支出合同-累计应付金额
DynamicObject taxRateObject = (DynamicObject)contract.get("taxrate");//支出合同-税率
BigDecimal taxRate = EcConstant.ZERO;
if (taxRateObject != null) {
taxRate = EcNumberHelper.toBigDecimal(taxRateObject.getBigDecimal("taxrate"));//税率-
}
BigDecimal thisApplyAmount = thisApplyOfTaxAmount.divide(BigDecimal.ONE.add(taxRate.divide(new BigDecimal(100))), 6, 5);
BigDecimal totalinvoiceAmount = contract.getBigDecimal("totalinvoiceamount");//支出合同-累计开票金额
BigDecimal totalInvoiceOftaxAmount = contract.getBigDecimal("totalinvoiceoftaxamount");//支出合同-累计开票价税合计
BigDecimal invoiceAmount = BigDecimal.ZERO;
BigDecimal invoiceOfTaxAmont = BigDecimal.ZERO;
DynamicObjectCollection subEntryCol = cont.getDynamicObjectCollection("subentryentity");//付款申请-进项发票信息
List<DynamicObject> invoiceList = new ArrayList(8);
DynamicObject invoice;
for(Iterator var23 = subEntryCol.iterator(); var23.hasNext(); invoiceList.add(invoice)) {
DynamicObject subentry = (DynamicObject)var23.next();
invoice = subentry.getDynamicObject("invoice");//发票号码
BigDecimal applyInvOftaxAmt = subentry.getBigDecimal("applyinvoftaxamt");//未申请含税金额
BigDecimal applyInvAmt = subentry.getBigDecimal("applyinvamt");//本次申请金额不含税
BigDecimal applyInvoiceTax = subentry.getBigDecimal("applyinvtax");//剩余税额
invoiceAmount = invoiceAmount.add(applyInvAmt);
invoiceOfTaxAmont = invoiceOfTaxAmont.add(applyInvOftaxAmt);
invoice = BusinessDataServiceHelper.loadSingle(invoice.getString("id"), "ec_in_invoice");//进项发票登记
BigDecimal invUnApplyAmt = invoice.getBigDecimal("unapplyamount");//进项发票登记-未申请含税金额
BigDecimal invoiceUnApplyTax = invoice.getBigDecimal("unapplyinvtax");//进项发票登记-剩余税额
if (operationKey.equals("audit")) {
invoice.set("unapplyamount", invUnApplyAmt.subtract(applyInvOftaxAmt));//进项发票登记-未申请含税金额
invoice.set("unapplyinvtax", invoiceUnApplyTax.subtract(applyInvoiceTax));//进项发票登记-剩余税额
} else if (StringUtils.equals(operationKey, "unaudit")) {
invoice.set("unapplyamount", invUnApplyAmt.add(applyInvOftaxAmt));//进项发票登记-未申请含税金额
invoice.set("unapplyinvtax", invoiceUnApplyTax.add(applyInvoiceTax));//进项发票登记-剩余税额
}
}
SaveServiceHelper.update((DynamicObject[])invoiceList.toArray(new DynamicObject[0]));//更新进项发票登记单
if (operationKey.equals("audit")) {
contract.set("totalapplyoftaxamount", totalApplyOfTaxAmount.add(thisApplyOfTaxAmount));//支出合同-累计应付含税金额
contract.set("totalapplyamount", totalApplyAmount.add(thisApplyAmount));//支出合同-累计应付金额
contract.set("totalinvoiceamount", totalinvoiceAmount.add(invoiceAmount));//支出合同-累计开票金额
contract.set("totalinvoiceoftaxamount", totalInvoiceOftaxAmount.add(invoiceOfTaxAmont).add(totalInvoiceAmount));//支出合同-累计开票价税合计
} else if (StringUtils.equals(operationKey, "unaudit")) {
contract.set("totalapplyoftaxamount", totalApplyOfTaxAmount.subtract(thisApplyOfTaxAmount));//支出合同-累计应付含税金额
contract.set("totalapplyamount", totalApplyAmount.subtract(thisApplyAmount));//支出合同-累计应付金额
contract.set("totalinvoiceamount", totalinvoiceAmount.subtract(invoiceAmount));//支出合同-累计开票金额
contract.set("totalinvoiceoftaxamount", totalInvoiceOftaxAmount.subtract(invoiceOfTaxAmont).subtract(totalInvoiceAmount));//支出合同-累计开票价税合计
}
}
}
}
}
}