From bed14f6699aba35376beffaf0fe54677046d0ebb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E8=B4=B5=E5=BC=BA?= Date: Thu, 29 May 2025 14:55:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=91=E7=A5=A8=E8=AF=86=E5=88=AB=E7=A8=8E?= =?UTF-8?q?=E7=8E=87*?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../formplugin/ReconPayreqFormPlugin.java | 33 ++++++++++++++----- .../dynamic/ReconPayreqNewFormPlugin.java | 22 ++++++++++--- 2 files changed, 42 insertions(+), 13 deletions(-) diff --git a/main/java/shkd/repc/recon/formplugin/ReconPayreqFormPlugin.java b/main/java/shkd/repc/recon/formplugin/ReconPayreqFormPlugin.java index 6d5d472..ec8588e 100644 --- a/main/java/shkd/repc/recon/formplugin/ReconPayreqFormPlugin.java +++ b/main/java/shkd/repc/recon/formplugin/ReconPayreqFormPlugin.java @@ -432,16 +432,31 @@ public class ReconPayreqFormPlugin extends AbstractFormPlugin implements BeforeF if (items != null){ for (int x = 0; x < items.size(); x++ ){ JSONObject item = items.getJSONObject(x); - if (item != null){ + if (item != null) { DynamicObject invoiceentr = invoiceentrs.addNew(); - invoiceentr.set("entry_content",item.getString("name"));//项目名称 - invoiceentr.set("entry_qty",item.getString("quantity"));//数量 - invoiceentr.set("entry_price",item.getString("price"));//单价 - invoiceentr.set("entry_notaxamt",item.getString("total"));//金额 - if (item.containsKey("tax_rate")){ - String tax_rate = item.getString("tax_rate"); - String substring = tax_rate.substring(0, tax_rate.length() - 1); - int value = Integer.parseInt(substring); + invoiceentr.set("entry_content", item.getString("name"));//项目名称 + invoiceentr.set("entry_qty", item.getString("quantity"));//数量 + invoiceentr.set("entry_price", item.getString("price"));//单价 + invoiceentr.set("entry_notaxamt", item.getString("total"));//金额 + + int value; // 默认值 + if (item.containsKey("tax_rate")) { // 先检查 key 是否存在 + try { + String taxRate = item.getString("tax_rate"); // 直接获取 + String numericPart; + if (taxRate.contains("*")) { + numericPart = "0"; + } else if (taxRate.endsWith("%")) { + numericPart = taxRate.substring(0, taxRate.length() - 1); + } else { + numericPart = taxRate; + } + + value = Integer.parseInt(numericPart); + } catch (Exception e) { + // 捕获 JSONException 或 NumberFormatException + value = 0; + } QFilter bd_taxrate_qf = new QFilter("taxrate",QCP.equals,value); DynamicObject bd_taxrate = BusinessDataServiceHelper.loadSingle("bd_taxrate", bd_taxrate_qf.toArray()); invoiceentr.set("entry_taxrate",bd_taxrate);//税率 diff --git a/main/java/shkd/repc/recon/formplugin/dynamic/ReconPayreqNewFormPlugin.java b/main/java/shkd/repc/recon/formplugin/dynamic/ReconPayreqNewFormPlugin.java index b64e8a4..10b5d8f 100644 --- a/main/java/shkd/repc/recon/formplugin/dynamic/ReconPayreqNewFormPlugin.java +++ b/main/java/shkd/repc/recon/formplugin/dynamic/ReconPayreqNewFormPlugin.java @@ -400,10 +400,24 @@ public class ReconPayreqNewFormPlugin extends AbstractFormPlugin implements Befo invoiceentr.set("entry_qty",item.getString("quantity"));//数量 invoiceentr.set("entry_price",item.getString("price"));//单价 invoiceentr.set("entry_notaxamt",item.getString("total"));//金额 - if (item.containsKey("tax_rate")){ - String tax_rate = item.getString("tax_rate"); - String substring = tax_rate.substring(0, tax_rate.length() - 1); - int value = Integer.parseInt(substring); + int value; // 默认值 + if (item.containsKey("tax_rate")) { // 先检查 key 是否存在 + try { + String taxRate = item.getString("tax_rate"); // 直接获取 + String numericPart; + if (taxRate.contains("*")) { + numericPart = "0"; + } else if (taxRate.endsWith("%")) { + numericPart = taxRate.substring(0, taxRate.length() - 1); + } else { + numericPart = taxRate; + } + + value = Integer.parseInt(numericPart); + } catch (Exception e) { + // 捕获 JSONException 或 NumberFormatException + value = 0; + } QFilter bd_taxrate_qf = new QFilter("taxrate",QCP.equals,value); DynamicObject bd_taxrate = BusinessDataServiceHelper.loadSingle("bd_taxrate", bd_taxrate_qf.toArray()); invoiceentr.set("entry_taxrate",bd_taxrate);//税率