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);//税率