From 48c0e86ff4e203cf5debb037027f5f4e6d9a3e75 Mon Sep 17 00:00:00 2001 From: zhangzhiguo <421587375@qq.com> Date: Fri, 7 Nov 2025 16:28:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=A5=E5=BA=93=E5=8D=95=E4=B8=8B=E6=8E=A8?= =?UTF-8?q?=E5=AF=B9=E5=85=AC=E6=8A=A5=E9=94=80=E5=8D=95=E5=8F=91=E7=A5=A8?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E8=A1=A5=E5=85=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MaterialinbillToNoContractBotpPlugin.java | 81 +++++++++++++++++-- 1 file changed, 74 insertions(+), 7 deletions(-) diff --git a/code/zcdev/zcgj-zcdev-zcdev-fs/src/main/java/zcgj/zcdev/zcdev/fs/plugin/other/MaterialinbillToNoContractBotpPlugin.java b/code/zcdev/zcgj-zcdev-zcdev-fs/src/main/java/zcgj/zcdev/zcdev/fs/plugin/other/MaterialinbillToNoContractBotpPlugin.java index 3c3c1b6..6b46afe 100644 --- a/code/zcdev/zcgj-zcdev-zcdev-fs/src/main/java/zcgj/zcdev/zcdev/fs/plugin/other/MaterialinbillToNoContractBotpPlugin.java +++ b/code/zcdev/zcgj-zcdev-zcdev-fs/src/main/java/zcgj/zcdev/zcdev/fs/plugin/other/MaterialinbillToNoContractBotpPlugin.java @@ -7,9 +7,13 @@ import kd.bos.dataentity.entity.DynamicObjectCollection; import kd.bos.entity.ExtendedDataEntity; import kd.bos.entity.botp.plugin.AbstractConvertPlugIn; import kd.bos.entity.botp.plugin.args.AfterConvertEventArgs; +import kd.bos.orm.query.QFilter; +import kd.bos.servicehelper.BusinessDataServiceHelper; import kd.bos.servicehelper.coderule.CodeRuleServiceHelper; import kd.bos.servicehelper.operation.SaveServiceHelper; +import java.math.BigDecimal; +import java.math.RoundingMode; import java.util.*; import java.util.stream.Collectors; @@ -37,12 +41,10 @@ public class MaterialinbillToNoContractBotpPlugin extends AbstractConvertPlugIn SaveServiceHelper.save(new DynamicObject[]{dataEntity}); Map invoiceEntryMap = new HashMap();//发票信息分录 Map expensEntryMap = new HashMap();//费用明细分录 - DynamicObjectCollection invoiceentry = dataEntity.getDynamicObjectCollection("invoiceentry"); - for (DynamicObject invoice : invoiceentry) { - String invoiceno = invoice.getString("invoiceno"); - long aLong = invoice.getLong("id"); - invoiceEntryMap.put(invoiceno, aLong); - } + Map invoiceDataEntryMap = new HashMap();//费用明细分录 + Map rimInvoiceDataEntryMap = new HashMap();//费用明细分录 + + //费用明细信息分录 DynamicObjectCollection expenseentryentity = dataEntity.getDynamicObjectCollection("expenseentryentity"); for (DynamicObject expenseentry : expenseentryentity) { String invoiceno = expenseentry.getString("invoiceno_entry"); @@ -50,17 +52,82 @@ public class MaterialinbillToNoContractBotpPlugin extends AbstractConvertPlugIn long aLong = expenseentry.getLong("id"); for (String invoiceNo : invoiceNos) { expensEntryMap.put(invoiceNo, aLong); + } } + //发票信息分录 + DynamicObjectCollection invoiceentry = dataEntity.getDynamicObjectCollection("invoiceentry"); + for (DynamicObject invoice : invoiceentry) { + String invoiceno = invoice.getString("invoiceno"); + long aLong = invoice.getLong("id"); + invoiceEntryMap.put(invoiceno, aLong); + invoiceDataEntryMap.put(invoiceno, invoice); + String serialno = invoice.getString("serialno"); + DynamicObject rimInvoice = BusinessDataServiceHelper.loadSingle("rim_invoice", "id,unitprice,invoice_amount,total_tax_amount,deduction_flag", + new QFilter[]{new QFilter("serial_no","=",serialno)}); + if(rimInvoice != null){ + rimInvoiceDataEntryMap.put(invoiceno, rimInvoice); + String deductionFlag = rimInvoice.getString("deduction_flag"); + if("1".equals(deductionFlag)){//可抵扣 + //是否抵扣 invoiceitemoffset 发票信息-是否抵扣 offset_invoice + invoice.set("offset_invoice",true); + }else{ + invoice.set("offset_invoice",false); + } + } + } + + //发票明细分录 DynamicObjectCollection invoiceitementry = dataEntity.getDynamicObjectCollection("invoiceitementry"); - for (String invoiceno : expensEntryMap.keySet()) { + for (String invoiceno : invoiceEntryMap.keySet()) {//以发票信息为主 Long itemid = expensEntryMap.get(invoiceno);//费用明细分录id Long invoiceId = invoiceEntryMap.get(invoiceno);//发票信息分录id DynamicObject dynamicObject = invoiceitementry.addNew();//发票明细,费用明细和发票信息关联关系 dynamicObject.set("itementryid", itemid); dynamicObject.set("invoiceheadentryid", invoiceId); + DynamicObject invoiceData = invoiceDataEntryMap.get(invoiceno); + DynamicObject rimInvoice = rimInvoiceDataEntryMap.get(invoiceno); + if(rimInvoice!=null){ + BigDecimal invoiceAmount = rimInvoice.getBigDecimal("invoice_amount");//发票金额-不含税金额 + + //不含税单价 unitprice + dynamicObject.set("unitprice", invoiceAmount); + + //不含税金额 excludeamount + dynamicObject.set("excludeamount", invoiceAmount); + + //税额 invoiceitemtaxamout 发票信息 + BigDecimal totalTaxAmount = rimInvoice.getBigDecimal("total_tax_amount");//发票税额 + dynamicObject.set("invoiceitemtaxamout", totalTaxAmount); + + //税率 invoiceitemtaxrate = 税额 ÷ 不含税金额 + if(invoiceAmount.compareTo(BigDecimal.ZERO)!=0){ + BigDecimal taxRate = totalTaxAmount.divide(invoiceAmount, 2, RoundingMode.HALF_UP); + dynamicObject.set("invoiceitemtaxrate", taxRate); + } + String deductionFlag = rimInvoice.getString("deduction_flag"); + if("1".equals(deductionFlag)){//可抵扣 + //是否抵扣 invoiceitemoffset 发票信息-是否抵扣 offset_invoice + dynamicObject.set("invoiceitemoffset",true); + //发票抵扣 invoicecloudoffset 发票信息-是否抵扣 offset_invoice + dynamicObject.set("invoicecloudoffset",true); + }else{ + //是否抵扣 invoiceitemoffset 发票信息-是否抵扣 offset_invoice + dynamicObject.set("invoiceitemoffset",false); + //发票抵扣 invoicecloudoffset 发票信息-是否抵扣 offset_invoice + dynamicObject.set("invoicecloudoffset",false); + } + } + + //商品名称 goodsname 发票信息-商品名称 invoicegoodsname + String invoicegoodsname = invoiceData.getString("invoicegoodsname"); + dynamicObject.set("goodsname", invoicegoodsname); + //税收分类编码 goodscode - 通过发票信息invoicealltaxcode 税收分类编码 查询 税收分类编码基础资料-合并编码er_taxclasscode-mergecode + //发票来源 invoicefrom1 发票信息-发票来源 1-发票云,2-OCR识别,3-商旅月结,5-采购商城 + dynamicObject.set("invoicefrom1",invoiceData.getString("invoicefrom")); + } SaveServiceHelper.save(new DynamicObject[]{dataEntity});