From 7c1ff840c939f904b01d2bbf02864ec563e6e57c Mon Sep 17 00:00:00 2001 From: mzr Date: Wed, 16 Apr 2025 15:04:41 +0800 Subject: [PATCH 01/11] =?UTF-8?q?=E5=88=B0=E8=B4=A6=E9=80=9A=E7=9F=A5?= =?UTF-8?q?=E5=8F=91=E5=B8=83-=E6=8E=A8=E9=80=81=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/cmp/informer/informer/action/myBtnClickAction.java | 1 + 1 file changed, 1 insertion(+) diff --git a/cmp/src/client/nccloud/web/cmp/informer/informer/action/myBtnClickAction.java b/cmp/src/client/nccloud/web/cmp/informer/informer/action/myBtnClickAction.java index 64d07342..2091f6ac 100644 --- a/cmp/src/client/nccloud/web/cmp/informer/informer/action/myBtnClickAction.java +++ b/cmp/src/client/nccloud/web/cmp/informer/informer/action/myBtnClickAction.java @@ -241,6 +241,7 @@ public class myBtnClickAction extends InformerAction implements ICommonAction { Map access_token = (Map) map.get("data"); String urls2 = urlpath + "/iuap-api-gateway/" + tenant + "/current_yonbip_default_sys/KKAPI/paymentNotice/addBatch?access_token=" + access_token.get("access_token"); Map mapjson = httpFW(urls2, jsonString1); + Logger.error("myBtnClickAction-jsonString1 = " + jsonString1); Logger.error("myBtnClickAction-mapjson = " + mapjson); if (!"200".equals(mapjson.getOrDefault("code", "") + "")) { throw new Exception(mapjson.getOrDefault("message", "推送失败") + ""); From 0fb90716534bbdbd6c932787d01580bef72c3936 Mon Sep 17 00:00:00 2001 From: mzr Date: Wed, 16 Apr 2025 15:58:18 +0800 Subject: [PATCH 02/11] =?UTF-8?q?=E5=88=B0=E8=B4=A6=E9=80=9A=E7=9F=A5?= =?UTF-8?q?=E5=8F=91=E5=B8=83-=E6=8E=A8=E9=80=81=E6=A0=87=E5=BF=97?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../informer/informer/action/myBtnClickAction.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cmp/src/client/nccloud/web/cmp/informer/informer/action/myBtnClickAction.java b/cmp/src/client/nccloud/web/cmp/informer/informer/action/myBtnClickAction.java index 2091f6ac..97bbb510 100644 --- a/cmp/src/client/nccloud/web/cmp/informer/informer/action/myBtnClickAction.java +++ b/cmp/src/client/nccloud/web/cmp/informer/informer/action/myBtnClickAction.java @@ -165,7 +165,7 @@ public class myBtnClickAction extends InformerAction implements ICommonAction { "ELSE '不存在' " + "END as direction, 'CNY' as currencyCode,moneyy , bant.code as dfcode,bant.name as dfname,oppbankaccount,bankt.accnum dfaccnum " + ",pk_oppunit,org.code as orgcode,org.name as orgname,cmp.pk_informer " + - ",cmp.memo,cmp.transerial,df.name as ksmc,df.code as ksbm,cmp.note_no,def01,cmp.oppunitname " + + ",cmp.memo,cmp.transerial,df.name as ksmc,df.code as ksbm,cmp.note_no,vdef1,cmp.oppunitname " + "from cmp_informer cmp " + "left join bd_bankaccbas bank on cmp.pk_bankacc=bank.pk_bankaccbas " + "left join bd_bankdoc ban on cmp.pk_bank=ban.pk_bankdoc " + @@ -182,13 +182,13 @@ public class myBtnClickAction extends InformerAction implements ICommonAction { for (int i = 0; i < results.size(); i++) { Map vmao = new HashMap(); Map row = results.get(i); - String def01 = (String) row.get("def01"); - if ("已推送".equals(def01)) { + String vdef1 = (String) row.get("vdef1"); + if ("已推送".equals(vdef1)) { resultMap.put("flag", "false"); resultMap.put("message", "已推送无法再次推送"); return resultMap; } - if ("撤回".equals(def01)) { + if ("撤回".equals(vdef1)) { vmao.put("publishStatus", "再次发布"); } else { vmao.put("publishStatus", ""); @@ -267,10 +267,10 @@ public class myBtnClickAction extends InformerAction implements ICommonAction { String pk_s = (String) pks.get(i); String sql1; if (successData != null && successData.contains(pk_s)) { - sql1 = "update cmp_informer set def01='已推送' where pk_informer='" + pk_s + "'"; + sql1 = "update cmp_informer set vdef1='已推送' where pk_informer='" + pk_s + "'"; sqlStr.add(sql1); } else { - sql1 = "update cmp_informer set def01='推送失败' where pk_informer='" + pk_s + "'"; + sql1 = "update cmp_informer set vdef1='推送失败' where pk_informer='" + pk_s + "'"; } sqlStr.add(sql1); From 7eafe36ea8dd9196802521227e8af30408a36fc2 Mon Sep 17 00:00:00 2001 From: mzr Date: Wed, 16 Apr 2025 16:32:42 +0800 Subject: [PATCH 03/11] =?UTF-8?q?2312=E4=B8=8A=E6=8E=A8=E9=80=81=E6=A0=87?= =?UTF-8?q?=E8=AF=86=E5=AD=97=E6=AE=B5=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/so/so/UpCdate/Updateinformer.java | 443 +++++++++--------- 1 file changed, 223 insertions(+), 220 deletions(-) diff --git a/so/src/public/nccloud/api/so/so/UpCdate/Updateinformer.java b/so/src/public/nccloud/api/so/so/UpCdate/Updateinformer.java index 80b7d554..03616085 100644 --- a/so/src/public/nccloud/api/so/so/UpCdate/Updateinformer.java +++ b/so/src/public/nccloud/api/so/so/UpCdate/Updateinformer.java @@ -1,6 +1,5 @@ package nccloud.api.so.so.UpCdate; -import nc.jdbc.framework.processor.MapListProcessor; -import org.springframework.util.ObjectUtils; + import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; @@ -10,13 +9,13 @@ import nc.itf.uap.IUAPQueryBS; import nc.jdbc.framework.JdbcSession; import nc.jdbc.framework.PersistenceManager; import nc.jdbc.framework.exception.DbException; -import nc.jdbc.framework.processor.ArrayListProcessor; import nc.jdbc.framework.processor.ColumnProcessor; +import nc.jdbc.framework.processor.MapListProcessor; import nc.vo.pub.BusinessException; import nccloud.api.rest.utils.ResultMessageUtil; import nccloud.ws.rest.resource.AbstractNCCRestResource; import org.json.JSONString; -import org.apache.http.client.methods.CloseableHttpResponse; + import javax.ws.rs.Consumes; import javax.ws.rs.POST; import javax.ws.rs.Path; @@ -27,86 +26,90 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import nc.itf.cm.productcostcollect.IProductCostCollectService; + +/** + * BIP流水3天内未认领退回NCC,并修改推送标识 + * 2005适配2312 + */ @Path("so/so/UpCdate") public class Updateinformer extends AbstractNCCRestResource { - @Override - public String getModule() { - return "so"; - } + @Override + public String getModule() { + return "so"; + } - // 用于存储手工维护的必填字段和字段说明 - private Map requiredFields; + // 用于存储手工维护的必填字段和字段说明 + private Map requiredFields; - // 构造方法,初始化必填字段及其说明 - public Updateinformer() { - // 初始化必填字段列表及字段说明 - requiredFields = new HashMap<>(); - requiredFields.put("pk_org", "业务单元"); - requiredFields.put("array.vbillcode", "单据编号"); - requiredFields.put("array.crowno", "行号"); - requiredFields.put("array.sendQty", "发货数量"); - } + // 构造方法,初始化必填字段及其说明 + public Updateinformer() { + // 初始化必填字段列表及字段说明 + requiredFields = new HashMap<>(); + requiredFields.put("pk_org", "业务单元"); + requiredFields.put("array.vbillcode", "单据编号"); + requiredFields.put("array.crowno", "行号"); + requiredFields.put("array.sendQty", "发货数量"); + } - @POST - @Path("/Updateinformer") - @Consumes({"application/json"}) - @Produces({"application/json"}) - public JSONString Updateinformer(JSONString json) { - JSONObject returnJson = new JSONObject(); - try { + @POST + @Path("/Updateinformer") + @Consumes({"application/json"}) + @Produces({"application/json"}) + public JSONString Updateinformer(JSONString json) { + JSONObject returnJson = new JSONObject(); + try { - JSONObject object = JSON.parseObject(json.toJSONString()); - if (object == null) { - return ResultMessageUtil.exceptionToJSON(new NullPointerException("JSONString:null")); - } - // 校验必填字段 + JSONObject object = JSON.parseObject(json.toJSONString()); + if (object == null) { + return ResultMessageUtil.exceptionToJSON(new NullPointerException("JSONString:null")); + } + // 校验必填字段 // String tipsStr = checkRequiredFields(object); // if (!tipsStr.equals("")) { // return ResultMessageUtil.exceptionToJSON(new NullPointerException(tipsStr)); // } - Object obj = object.getOrDefault("array", ""); + Object obj = object.getOrDefault("array", ""); if (obj.equals("")) { return ResultMessageUtil.exceptionToJSON(new NullPointerException("array:null")); } - ArrayList arrayList = new ArrayList<>(); - if (obj instanceof JSONArray) { - JSONArray jsonArray = (JSONArray) obj; - arrayList = new ArrayList<>(jsonArray.toJavaList(Object.class)); - } + ArrayList arrayList = new ArrayList<>(); + if (obj instanceof JSONArray) { + JSONArray jsonArray = (JSONArray) obj; + arrayList = new ArrayList<>(jsonArray.toJavaList(Object.class)); + } // StringBuilder sqlStr = new StringBuilder(); - List sqlStr = new ArrayList(); - ArrayList pk_list=null; + List sqlStr = new ArrayList(); + ArrayList pk_list = null; // for (int i = 0; i < arrayList.size(); i++) { // Map dataMap = (Map) arrayList.get(i); // pk_list.add((String) dataMap.get("pk_informer")); // } - String result = ""; - StringBuilder sb = new StringBuilder(); - if (arrayList.size() > 1) { - for (int i = 0; i < arrayList.size(); i++) { - Map dataMap = (Map) arrayList.get(i); + String result = ""; + StringBuilder sb = new StringBuilder(); + if (arrayList.size() > 1) { + for (int i = 0; i < arrayList.size(); i++) { + Map dataMap = (Map) arrayList.get(i); - sb.append("'").append(dataMap.get("pk_informer")).append("'"); - if (i < arrayList.size() - 1) { - sb.append(","); - } - } + sb.append("'").append(dataMap.get("pk_informer")).append("'"); + if (i < arrayList.size() - 1) { + sb.append(","); + } + } - result = sb.toString(); - }else { - Map dataMap = (Map) arrayList.get(0); + result = sb.toString(); + } else { + Map dataMap = (Map) arrayList.get(0); - result= "'"+(String) dataMap.get("pk_informer")+"'"; + result = "'" + (String) dataMap.get("pk_informer") + "'"; - } - String sqlser="select pk_informer from cmp_informer where pk_informer in("+result+")"; + } + String sqlser = "select pk_informer from cmp_informer where pk_informer in(" + result + ")"; // ArrayList results = (ArrayList) getQueryService().executeQuery(sqlser, new ArrayListProcessor()); - List> results = (List>) getQueryService().executeQuery(sqlser, new MapListProcessor()); + List> results = (List>) getQueryService().executeQuery(sqlser, new MapListProcessor()); // if (results != null || results.size()!=arrayList.size()) { // vbillcodes.add(dataMap.get("pk_informer")); // }else { @@ -114,190 +117,190 @@ public class Updateinformer extends AbstractNCCRestResource { // returnJson.put("msg", "失败,"+dataMap.get("pk_informer")+"不存在"); // return (JSONString) returnJson; // } - ArrayList result2 = new ArrayList<>(); - System.out.println(results.getClass()); - for (int i = 0; i < results.size(); i++) { - Map aa=results.get(i); - result2.add((String) aa.get("pk_informer")); - } - ArrayList vbillcodes = new ArrayList<>(); - for (int i = 0; i < arrayList.size(); i++) { - Map dataMap = (Map) arrayList.get(i); - Object pkInformer = dataMap.get("pk_informer"); - Object status = dataMap.get("status"); + ArrayList result2 = new ArrayList<>(); + System.out.println(results.getClass()); + for (int i = 0; i < results.size(); i++) { + Map aa = results.get(i); + result2.add((String) aa.get("pk_informer")); + } + ArrayList vbillcodes = new ArrayList<>(); + for (int i = 0; i < arrayList.size(); i++) { + Map dataMap = (Map) arrayList.get(i); + Object pkInformer = dataMap.get("pk_informer"); + Object status = dataMap.get("status"); - if (pkInformer == null || status == null) { - continue; // 处理 null 值 - } - //判断字符串在不在results查询对象里面 - //将results里面的所有值改为string类型 + if (pkInformer == null || status == null) { + continue; // 处理 null 值 + } + // 判断字符串在不在results查询对象里面 + // 将results里面的所有值改为string类型 - String pk_informer= (String) dataMap.get("pk_informer"); + String pk_informer = (String) dataMap.get("pk_informer"); if (result2.contains(pk_informer)) { - vbillcodes.add(dataMap.get("pk_informer")); + vbillcodes.add(dataMap.get("pk_informer")); - sqlStr.add("UPDATE cmp_informer SET def01 = '" + dataMap.get("status") + "' where pk_informer='"+dataMap.get("pk_informer") - + "';"); - } - } - returnJson.put("codeList", vbillcodes); + sqlStr.add("UPDATE cmp_informer SET vdef1 = '" + dataMap.get("status") + "' where pk_informer='" + dataMap.get("pk_informer") + + "';"); + } + } + returnJson.put("codeList", vbillcodes); - int succState = executeUpdate(sqlStr); + int succState = executeUpdate(sqlStr); - returnJson.put("state", '1'); - if (succState == 0) { - returnJson.put("msg", "失败"); - }else { - returnJson.put("msg", "成功,已修改"+succState+"行"); + returnJson.put("state", '1'); + if (succState == 0) { + returnJson.put("msg", "失败"); + } else { + returnJson.put("msg", "成功,已修改" + succState + "行"); - } - return ResultMessageUtil.toJSON(returnJson); - } catch (DbException e) { - throw new RuntimeException(e); - } catch (Exception e) { - throw new RuntimeException(e); - } - } + } + return ResultMessageUtil.toJSON(returnJson); + } catch (DbException e) { + throw new RuntimeException(e); + } catch (Exception e) { + throw new RuntimeException(e); + } + } - /** - * updateSqls为要执行的sql语句。返回影响行数量 - */ - public int executeUpdate(List updateSqls) throws DbException { - if (updateSqls == null) { - return 0; - } + /** + * updateSqls为要执行的sql语句。返回影响行数量 + */ + public int executeUpdate(List updateSqls) throws DbException { + if (updateSqls == null) { + return 0; + } - int ret = 0; - PersistenceManager manager = null; - JdbcSession session = null; - Connection connection = null; + int ret = 0; + PersistenceManager manager = null; + JdbcSession session = null; + Connection connection = null; - try { - manager = PersistenceManager.getInstance(); - session = manager.getJdbcSession(); - connection = session.getConnection(); // 获取实际的数据库连接 + try { + manager = PersistenceManager.getInstance(); + session = manager.getJdbcSession(); + connection = session.getConnection(); // 获取实际的数据库连接 - // 开始事务 - connection.setAutoCommit(false); // 禁用自动提交,手动管理事务 + // 开始事务 + connection.setAutoCommit(false); // 禁用自动提交,手动管理事务 - // 执行批量操作 - for (String sql : updateSqls) { - session.addBatch(sql); - } + // 执行批量操作 + for (String sql : updateSqls) { + session.addBatch(sql); + } - // 执行批处理 - ret = session.executeBatch(); + // 执行批处理 + ret = session.executeBatch(); - // 提交事务 - connection.commit(); // 批处理成功后提交事务 + // 提交事务 + connection.commit(); // 批处理成功后提交事务 - } catch (DbException e) { - if (connection != null) { - try { - // 如果发生异常,回滚事务 - connection.rollback(); - } catch (SQLException rollbackEx) { - // 记录回滚异常的详细信息 - throw new DbException("Error during transaction rollback", rollbackEx) { - @Override - public boolean isDataIntegrityViolation() { - return false; - } + } catch (DbException e) { + if (connection != null) { + try { + // 如果发生异常,回滚事务 + connection.rollback(); + } catch (SQLException rollbackEx) { + // 记录回滚异常的详细信息 + throw new DbException("Error during transaction rollback", rollbackEx) { + @Override + public boolean isDataIntegrityViolation() { + return false; + } - @Override - public boolean isBadSQLGrammar() { - return false; - } - }; - } - } - throw e; // 将原始异常抛出 - } catch (SQLException e) { - throw new RuntimeException(e); - } finally { - if (connection != null) { - try { - // 恢复自动提交模式,确保不会影响其他操作 - connection.setAutoCommit(true); - } catch (SQLException e) { - // 忽略恢复自动提交时的异常 - } - } - if (manager != null) { - manager.release(); - } - } + @Override + public boolean isBadSQLGrammar() { + return false; + } + }; + } + } + throw e; // 将原始异常抛出 + } catch (SQLException e) { + throw new RuntimeException(e); + } finally { + if (connection != null) { + try { + // 恢复自动提交模式,确保不会影响其他操作 + connection.setAutoCommit(true); + } catch (SQLException e) { + // 忽略恢复自动提交时的异常 + } + } + if (manager != null) { + manager.release(); + } + } - return ret; - } + return ret; + } - // 方法:检查必填项并返回转化后的Map - public static String checkRequiredFields(JSONObject data) throws Exception { - String returnStr = ""; - // 2. 检查必填字段 pk_org - String pkOrg = (String) data.getOrDefault("pk_org", ""); - if (pkOrg.isEmpty()) { - return "字段pk_org缺失或为空!"; - } - // 3. 获取并检查 array 字段 - Object array = data.getOrDefault("array", null); - if (array == null || !(array instanceof JSONArray) || ((JSONArray) array).isEmpty()) { - return "array对象为空或不存在!"; - } - ArrayList arrayList = new ArrayList<>(); - if (array instanceof JSONArray) { - JSONArray jsonArray = (JSONArray) array; - arrayList = new ArrayList<>(jsonArray.toJavaList(Object.class)); - } - // 5. 遍历每个对象,检查必填字段 - for (int i = 0; i < arrayList.size(); i++) { - Map item = (Map) arrayList.get(i); - // 检查必填字段 'crowno' - if (item.getOrDefault("crowno", "").toString().isEmpty()) { - return "第 " + (i + 1) + " 项缺少必填字段crowno!"; - } - // 检查必填字段 'vbillcode' - if (item.getOrDefault("vbillcode", "").toString().isEmpty()) { - return "第 " + (i + 1) + " 项缺少必填字段vbillcode!"; - } - // 检查必填字段 'sendQty' - if (item.getOrDefault("sendQty", "").toString().isEmpty()) { - return "第 " + (i + 1) + " 项缺少必填字段sendQty!"; - } - } - return returnStr; - } + // 方法:检查必填项并返回转化后的Map + public static String checkRequiredFields(JSONObject data) throws Exception { + String returnStr = ""; + // 2. 检查必填字段 pk_org + String pkOrg = (String) data.getOrDefault("pk_org", ""); + if (pkOrg.isEmpty()) { + return "字段pk_org缺失或为空!"; + } + // 3. 获取并检查 array 字段 + Object array = data.getOrDefault("array", null); + if (array == null || !(array instanceof JSONArray) || ((JSONArray) array).isEmpty()) { + return "array对象为空或不存在!"; + } + ArrayList arrayList = new ArrayList<>(); + if (array instanceof JSONArray) { + JSONArray jsonArray = (JSONArray) array; + arrayList = new ArrayList<>(jsonArray.toJavaList(Object.class)); + } + // 5. 遍历每个对象,检查必填字段 + for (int i = 0; i < arrayList.size(); i++) { + Map item = (Map) arrayList.get(i); + // 检查必填字段 'crowno' + if (item.getOrDefault("crowno", "").toString().isEmpty()) { + return "第 " + (i + 1) + " 项缺少必填字段crowno!"; + } + // 检查必填字段 'vbillcode' + if (item.getOrDefault("vbillcode", "").toString().isEmpty()) { + return "第 " + (i + 1) + " 项缺少必填字段vbillcode!"; + } + // 检查必填字段 'sendQty' + if (item.getOrDefault("sendQty", "").toString().isEmpty()) { + return "第 " + (i + 1) + " 项缺少必填字段sendQty!"; + } + } + return returnStr; + } - /* - *创建时间:2024-11-28 - *作用:查询 - *传值:无 - *返回值:必填项map对象 - */ - private String getSaleorderBPK(String pk_org, String vbillcode, String crowno) throws BusinessException { - String sql = " select b.csaleorderbid from so_saleorder h \n" - + "left join so_saleorder_b b on h.csaleorderid=b.csaleorderid\n" - + "left join org_salesorg o on h.pk_org=o.pk_salesorg\n" - + "where h.vbillcode='" + vbillcode + "' and o.code='" + pk_org + "' and b.crowno='" + crowno + "' "; - String saleorderBPK = (String) getQueryService().executeQuery(sql, new ColumnProcessor()); - return saleorderBPK; - } + /* + *创建时间:2024-11-28 + *作用:查询 + *传值:无 + *返回值:必填项map对象 + */ + private String getSaleorderBPK(String pk_org, String vbillcode, String crowno) throws BusinessException { + String sql = " select b.csaleorderbid from so_saleorder h \n" + + "left join so_saleorder_b b on h.csaleorderid=b.csaleorderid\n" + + "left join org_salesorg o on h.pk_org=o.pk_salesorg\n" + + "where h.vbillcode='" + vbillcode + "' and o.code='" + pk_org + "' and b.crowno='" + crowno + "' "; + String saleorderBPK = (String) getQueryService().executeQuery(sql, new ColumnProcessor()); + return saleorderBPK; + } - /* - *创建时间:2024-11-28 - *作用:查询 - *传值:无 - *返回值:必填项map对象 - */ - private int updateSaleBSQty(String sql) throws BusinessException { - BaseDAO baseDAO = new BaseDAO(); - int succInt = baseDAO.executeUpdate(sql); - return succInt; - } + /* + *创建时间:2024-11-28 + *作用:查询 + *传值:无 + *返回值:必填项map对象 + */ + private int updateSaleBSQty(String sql) throws BusinessException { + BaseDAO baseDAO = new BaseDAO(); + int succInt = baseDAO.executeUpdate(sql); + return succInt; + } - public IUAPQueryBS getQueryService() { - return NCLocator.getInstance().lookup(IUAPQueryBS.class); - } + public IUAPQueryBS getQueryService() { + return NCLocator.getInstance().lookup(IUAPQueryBS.class); + } } From 4a5bf28ef34317cfab9c66babe18177dd08ee3e1 Mon Sep 17 00:00:00 2001 From: mzr Date: Wed, 16 Apr 2025 18:32:39 +0800 Subject: [PATCH 04/11] =?UTF-8?q?=E9=94=80=E5=94=AE=E5=8F=91=E7=A5=A8?= =?UTF-8?q?=E7=BA=A2=E5=86=B2=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{saleinvoice.rest => SaleRedInv.rest} | 0 so/META-INF/saveCommit.rest | 6 +++--- .../saleinvoice/operator/BillSaveAction.java | 21 +++++++++++++------ 3 files changed, 18 insertions(+), 9 deletions(-) rename so/META-INF/{saleinvoice.rest => SaleRedInv.rest} (100%) diff --git a/so/META-INF/saleinvoice.rest b/so/META-INF/SaleRedInv.rest similarity index 100% rename from so/META-INF/saleinvoice.rest rename to so/META-INF/SaleRedInv.rest diff --git a/so/META-INF/saveCommit.rest b/so/META-INF/saveCommit.rest index 10db0a06..52fd99a9 100644 --- a/so/META-INF/saveCommit.rest +++ b/so/META-INF/saveCommit.rest @@ -1,6 +1,6 @@ - - - + + + \ No newline at end of file diff --git a/so/src/public/nccloud/api/so/saleinvoice/operator/BillSaveAction.java b/so/src/public/nccloud/api/so/saleinvoice/operator/BillSaveAction.java index 7b706c61..9fe5a050 100644 --- a/so/src/public/nccloud/api/so/saleinvoice/operator/BillSaveAction.java +++ b/so/src/public/nccloud/api/so/saleinvoice/operator/BillSaveAction.java @@ -3,7 +3,6 @@ package nccloud.api.so.saleinvoice.operator; import com.alibaba.fastjson.JSONObject; import nc.bs.framework.common.NCLocator; import nc.bs.framework.core.util.ObjectCreator; -import nc.bs.ia.audit.pub.CloneUtil; import nc.bs.logging.Logger; import nc.bs.trade.business.HYSuperDMO; import nc.itf.uap.IUAPQueryBS; @@ -12,6 +11,7 @@ import nc.vo.pub.BusinessException; import nc.vo.pub.lang.UFBoolean; import nc.vo.pub.lang.UFDate; import nc.vo.pub.lang.UFDouble; +import nc.vo.pubapp.pattern.tool.performance.DeepCloneTool; import nc.vo.scmpub.res.billtype.SOBillType; import nc.vo.so.m32.entity.SaleInvoiceBVO; import nc.vo.so.m32.entity.SaleInvoiceHVO; @@ -47,6 +47,15 @@ public class BillSaveAction extends AbstractNCCRestResource { public static String fplxStr = "";// 开票申请发票类型 + public static DeepCloneTool deepCloneTool; + + public static DeepCloneTool getCloneTool() { + if (deepCloneTool == null) { + deepCloneTool = new DeepCloneTool(); + } + return deepCloneTool; + } + public BillSaveAction() { } @@ -199,7 +208,7 @@ public class BillSaveAction extends AbstractNCCRestResource { JSONObject bipBvoJson = newBvoArr.get(0); // 参数子表 SaleInvoiceBVO newInvBVO = new SaleInvoiceBVO(); // 克隆取值原子表销售发票 - newInvBVO = (SaleInvoiceBVO) CloneUtil.depthClone(saleInvoiceBVO); + newInvBVO = (SaleInvoiceBVO) getCloneTool().deepClone(saleInvoiceBVO); // 赋值之后修改子实体红冲时字段 newInvBVO.setCsaleinvoicebid(null); // 发票子实体id newInvBVO.setDbilldate(dbilldate); // 开票日期 @@ -227,7 +236,7 @@ public class BillSaveAction extends AbstractNCCRestResource { } // 克隆取值原子表销售发票 - newSaleInvoiceHVO = (SaleInvoiceHVO) CloneUtil.depthClone(saleInvoiceHVO); + newSaleInvoiceHVO = (SaleInvoiceHVO) getCloneTool().deepClone(saleInvoiceHVO); // 赋值之后修改主实体红冲时字段 newSaleInvoiceHVO.setCsaleinvoiceid(null); // 发票主实体id newSaleInvoiceHVO.setVbillcode(null); // 发票号 @@ -256,7 +265,7 @@ public class BillSaveAction extends AbstractNCCRestResource { /** * 构造红冲开票申请VO * - * @param applyHeadVO 原开票申请主实体 + * @param applyHeadVO 原开票申请主实体 * @param ivApplicationBodyVOS 原开票申请子实体 * @param bject bip参数 * @param returnApproveSaleInvoiceVOs 新生成的红冲销售发票实体 @@ -277,7 +286,7 @@ public class BillSaveAction extends AbstractNCCRestResource { // 主实体属性赋值 // 克隆取值原子表开票申请 - newivApplicationHeadVO = (IVApplicationHeadVO) CloneUtil.depthClone(applyHeadVO); + newivApplicationHeadVO = (IVApplicationHeadVO) getCloneTool().deepClone(applyHeadVO); // 根据参数判断是否为部分红冲 boolean isPartHCFlag = false; UFDouble paramNtotalorigmny = new UFDouble(bject.getString("ntotalorigmny")); // 参数价税合计(主表红冲金额) @@ -311,7 +320,7 @@ public class BillSaveAction extends AbstractNCCRestResource { IVApplicationBodyVO newivApplicationBodyVO = new IVApplicationBodyVO(); // BeanUtil.copyProperties(ivApplicationBodyVO,newivApplicationBodyVO, CopyOptions.create().setIgnoreNullValue(true)); // 克隆取值原子表开票申请 - newivApplicationBodyVO = (IVApplicationBodyVO) CloneUtil.depthClone(ivApplicationBodyVO); + newivApplicationBodyVO = (IVApplicationBodyVO) getCloneTool().deepClone(ivApplicationBodyVO); // 赋值之后修改子实体红冲时字段 newivApplicationBodyVO.setPk_ivappdetail(null); // 开票申请子实体id newivApplicationBodyVO.setBillno(null); // 开票申请子实体单据号 From 9033478c9342cccaba8c06645f2c4564924030ef Mon Sep 17 00:00:00 2001 From: mzr Date: Thu, 17 Apr 2025 10:28:33 +0800 Subject: [PATCH 05/11] =?UTF-8?q?=E6=94=B6=E6=AC=BE=E6=96=B0=E5=A2=9E-?= =?UTF-8?q?=E5=B8=81=E7=A7=8D=E6=8E=A5=E6=94=B6BIP=E5=90=88=E5=90=8C?= =?UTF-8?q?=E5=B9=B3=E5=8F=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../arap/resource/GatheringbillRestResource.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/arap/src/public/nc/api/arap/resource/GatheringbillRestResource.java b/arap/src/public/nc/api/arap/resource/GatheringbillRestResource.java index a31a86bd..73dd35c7 100644 --- a/arap/src/public/nc/api/arap/resource/GatheringbillRestResource.java +++ b/arap/src/public/nc/api/arap/resource/GatheringbillRestResource.java @@ -143,7 +143,7 @@ public class GatheringbillRestResource extends ArapBaseRestResource { Object ctaxcodeid = hybo.findColValue("so_saleorder_b", "ctaxcodeid", "csaleorderid = '" + csaleorderid + "' "); Object tc = hybo.findColValue("bd_taxcode", "code", "pk_taxcode = '" + ctaxcodeid + "' "); - ctaxcode = tc.toString(); + ctaxcode = getString_TrimAsNull(tc); // 业务员 Object cemployeeid = hybo.findColValue("so_saleorder", "cemployeeid", "csaleorderid = '" + csaleorderid + "' "); @@ -160,7 +160,10 @@ public class GatheringbillRestResource extends ArapBaseRestResource { } } // pk_currtype 币种编码 默认人民币 - headvo.setPk_currtype("CNY"); + if (headvo.getPk_currtype() == null || headvo.getPk_currtype().isEmpty()) { + headvo.setPk_currtype("CNY"); + } + // accessorynum 附件张数 默认2 headvo.setAccessorynum(2); // 制单人 默认BIP @@ -769,4 +772,12 @@ public class GatheringbillRestResource extends ArapBaseRestResource { return ResultMessageUtil.exceptionToJSON(e); } } + + public static String getString_TrimAsNull(Object value) { + if ((value == null) || (value.toString().trim().length() == 0)) { + return ""; + } + return value.toString().trim(); + } + } From 99abe02779716465c238d112233594074035d1bc Mon Sep 17 00:00:00 2001 From: mzr Date: Thu, 17 Apr 2025 10:42:27 +0800 Subject: [PATCH 06/11] =?UTF-8?q?=E9=94=80=E5=94=AE=E5=8F=91=E7=A5=A8?= =?UTF-8?q?=E7=BA=A2=E5=86=B2=E6=8E=A5=E5=8F=A3=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../saleinvoice/operator/BillSaveAction.java | 46 +++++++++++++++---- 1 file changed, 37 insertions(+), 9 deletions(-) diff --git a/so/src/public/nccloud/api/so/saleinvoice/operator/BillSaveAction.java b/so/src/public/nccloud/api/so/saleinvoice/operator/BillSaveAction.java index 9fe5a050..2d10b235 100644 --- a/so/src/public/nccloud/api/so/saleinvoice/operator/BillSaveAction.java +++ b/so/src/public/nccloud/api/so/saleinvoice/operator/BillSaveAction.java @@ -1,16 +1,19 @@ package nccloud.api.so.saleinvoice.operator; +import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import nc.bs.framework.common.NCLocator; import nc.bs.framework.core.util.ObjectCreator; import nc.bs.logging.Logger; import nc.bs.trade.business.HYSuperDMO; import nc.itf.uap.IUAPQueryBS; +import nc.jdbc.framework.processor.MapProcessor; import nc.pubitf.so.m32.api.ISaleinvoiceQueryAPI; import nc.vo.pub.BusinessException; import nc.vo.pub.lang.UFBoolean; import nc.vo.pub.lang.UFDate; import nc.vo.pub.lang.UFDouble; +import nc.vo.pubapp.calculator.HslParseUtil; import nc.vo.pubapp.pattern.tool.performance.DeepCloneTool; import nc.vo.scmpub.res.billtype.SOBillType; import nc.vo.so.m32.entity.SaleInvoiceBVO; @@ -23,6 +26,7 @@ import nccloud.api.baseapp.exchange.convert.IExchangeForService; import nccloud.api.baseapp.exchange.convert.OpenApiConvertDataObject; import nccloud.api.baseapp.exchange.convert.OpenApiConvertDataResult; import nccloud.api.rest.utils.ResultMessageUtil; +import nccloud.commons.lang.StringUtils; import nccloud.itf.sscivm.ivsale.impl.IVApplicationServiceImpl; import nccloud.pubitf.riart.pflow.CloudPFlowContext; import nccloud.pubitf.riart.pflow.ICloudScriptPFlowService; @@ -34,6 +38,7 @@ import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.Produces; import java.util.List; +import java.util.Map; /** * 销售发票红冲接口 @@ -113,8 +118,9 @@ public class BillSaveAction extends AbstractNCCRestResource { context.setBillVos(new SaleInvoiceVO[]{saleInvoiceRedRushVO}); context.setActionName("WRITE"); SaleInvoiceVO[] returnSaveSaleInvoiceVOs = (SaleInvoiceVO[]) flowService.exeScriptPFlow(context); -// SaleInvoiceVO[] returnSaveSaleInvoiceVO = (SaleInvoiceVO[])PfServiceScmUtil.processBatch("WRITE", SOBillType.Invoice.getCode(), new SaleInvoiceVO[] { saleInvoiceRedRushVO }, null, null); + Logger.error("=========================inv-save============== "); if (returnSaveSaleInvoiceVOs != null && returnSaveSaleInvoiceVOs.length > 0) { + Logger.error("inv-save = " + JSONArray.toJSONString(returnSaveSaleInvoiceVOs)); // 生成红冲发票成功后,执行销售发票审批动作 context.setBillType("32"); context.setBillVos(returnSaveSaleInvoiceVOs); @@ -123,6 +129,8 @@ public class BillSaveAction extends AbstractNCCRestResource { if (returnApproveSaleInvoiceVOs == null || returnApproveSaleInvoiceVOs.length <= 0) { throw new BusinessException("生成销售发票审核失败"); } + Logger.error("=========================inv-audit============== "); + Logger.error("inv-audit = " + JSONArray.toJSONString(returnApproveSaleInvoiceVOs)); /** * 开票申请红冲逻辑: * 1.根据销售发票号查询下游开票申请 @@ -138,13 +146,8 @@ public class BillSaveAction extends AbstractNCCRestResource { // 调用函数封装开票申请红冲VO IVApplicationAggVO iVApplicationAggVO = makeNewRedRushIVApplicationAggVO(iVApplicationHeadVO[0], iVApplicationBodyVOs, bject, returnApproveSaleInvoiceVOs); // 生成红冲的开票申请 -// context.setBillType("SSCIVA"); -// context.setBillVos( new IVApplicationAggVO[] { iVApplicationAggVO }); -// context.setActionName("SAVE"); -// IVApplicationAggVO[] returnSaveIVApplicationAggVO = (IVApplicationAggVO[] )flowService.exeScriptPFlow(context); IVApplicationServiceImpl serviceImpl = new IVApplicationServiceImpl(); IVApplicationAggVO returnSaveIVApplicationAggVO = serviceImpl.save(iVApplicationAggVO); -// Object returnIVApplicationAggVO = PfServiceScmUtil.processBatch("SAVE", "SSCIVA", new IVApplicationAggVO[] { iVApplicationAggVO }, null, null); if (returnSaveIVApplicationAggVO != null) { return ResultMessageUtil.toJSON(returnApproveSaleInvoiceVOs, "接口调用成功"); } else { @@ -212,8 +215,21 @@ public class BillSaveAction extends AbstractNCCRestResource { // 赋值之后修改子实体红冲时字段 newInvBVO.setCsaleinvoicebid(null); // 发票子实体id newInvBVO.setDbilldate(dbilldate); // 开票日期 - newInvBVO.setNastnum(new UFDouble(bipBvoJson.getString("nastnum"))); // 数量 - newInvBVO.setNnum(new UFDouble(bipBvoJson.getString("nnum"))); // 主数量 + String vchangerate = "1/1"; // 换算率 + Map soMap = getSaleOrderInfo(bipBvoJson.getString("csrcbid")); + if (soMap != null && StringUtils.isNotEmpty(soMap.getOrDefault("vchangerate", "") + "")) { + vchangerate = soMap.get("vchangerate") + ""; // 销售订单的换算率 + } + newInvBVO.setVchangerate(vchangerate); // 换算率 + UFDouble[] vchangerateNums = HslParseUtil.parseHsl(vchangerate); + UFDouble vchangerateNum = UFDouble.ONE_DBL; + if (null != vchangerateNums && vchangerateNums.length != 0) { + vchangerateNum = vchangerateNums[0].div(vchangerateNums[1]).setScale(2, 4); + } + // BIP合同平台的数量对应BIP2312的主数量,BIP2312的 数量=主数量*换算关系 + UFDouble nastnum = new UFDouble(bipBvoJson.getString("nastnum")); + newInvBVO.setNastnum(nastnum.multiply(vchangerateNum).setScale(2, 4)); // 数量 + newInvBVO.setNnum(nastnum); // 主数量 newInvBVO.setNtax(new UFDouble(bipBvoJson.getString("ntax"))); // 税额 newInvBVO.setNmny(new UFDouble(bipBvoJson.getString("nmny"))); // 本币无税金额 newInvBVO.setNtaxmny(new UFDouble(bipBvoJson.getString("ntaxmny"))); // 本币价税合计 @@ -226,7 +242,6 @@ public class BillSaveAction extends AbstractNCCRestResource { newInvBVO.setNtotalcostnum(null); // 累计成本结算数量 newInvBVO.setNtotalincomemny(null); // 累计确认应收金额 newInvBVO.setNtotalincomenum(null); // 累计确认应收数量 - newInvBVO.setVchangerate("1.00/1.00"); // 换算率 newSaleInvoiceBVOs[i++] = newInvBVO; sumNum = sumNum.add(new UFDouble(bipBvoJson.getString("nnum"))); sumNtax = sumNtax.add(new UFDouble(bipBvoJson.getString("ntax"))); @@ -366,4 +381,17 @@ public class BillSaveAction extends AbstractNCCRestResource { return NCLocator.getInstance().lookup(IUAPQueryBS.class); } + + private static Map getSaleOrderInfo(String csaleorderbid) throws BusinessException { + IUAPQueryBS queryBS = NCLocator.getInstance().lookup(IUAPQueryBS.class); + String sql = " select s.vbillcode,s.csaleorderid, s.corigcurrencyid," + + " sb.csaleorderbid,sb.crowno,sb.blargessflag,sb.nexchangerate," + + " nvl(sb.vchangerate, '1/1') vchangerate, bdc.code currencycode" + + " from so_saleorder_b sb" + + " inner join so_saleorder s on sb.csaleorderid=s.csaleorderid" + + " left join bd_currtype bdc on s.corigcurrencyid=bdc.pk_currtype" + + " where sb.csaleorderbid='" + csaleorderbid + "' "; + return (Map) queryBS.executeQuery(sql, new MapProcessor()); + } + } \ No newline at end of file From 6e7f80cab56bda9e19ceddfc5c145384615775b0 Mon Sep 17 00:00:00 2001 From: mzr Date: Thu, 17 Apr 2025 15:41:26 +0800 Subject: [PATCH 07/11] =?UTF-8?q?=E9=94=80=E5=94=AE=E5=8F=91=E7=A5=A8?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E4=BB=A3=E7=A0=81=E5=90=88=E5=B9=B6=EF=BC=8C?= =?UTF-8?q?=E7=94=A82=E4=B8=AAResource=E4=BC=9A=E6=8F=90=E7=A4=BA:resource?= =?UTF-8?q?=20notfound,please=20check=20path?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- so/META-INF/{saveCommit.rest => SaleInv.rest} | 2 +- so/META-INF/SaleRedInv.rest | 6 - .../saleinvoice/operator/BillSaveAction.java | 397 ----------- .../operator/IAPISaleInvMaitainImpl.java | 645 ++++++++++++++++++ .../saleinvoice/operator/SaleInvResource.java | 76 +++ .../operator/saveCommitAction.java | 431 ------------ 6 files changed, 722 insertions(+), 835 deletions(-) rename so/META-INF/{saveCommit.rest => SaleInv.rest} (64%) delete mode 100644 so/META-INF/SaleRedInv.rest delete mode 100644 so/src/public/nccloud/api/so/saleinvoice/operator/BillSaveAction.java create mode 100644 so/src/public/nccloud/api/so/saleinvoice/operator/IAPISaleInvMaitainImpl.java create mode 100644 so/src/public/nccloud/api/so/saleinvoice/operator/SaleInvResource.java delete mode 100644 so/src/public/nccloud/api/so/saleinvoice/operator/saveCommitAction.java diff --git a/so/META-INF/saveCommit.rest b/so/META-INF/SaleInv.rest similarity index 64% rename from so/META-INF/saveCommit.rest rename to so/META-INF/SaleInv.rest index 52fd99a9..2376205a 100644 --- a/so/META-INF/saveCommit.rest +++ b/so/META-INF/SaleInv.rest @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/so/META-INF/SaleRedInv.rest b/so/META-INF/SaleRedInv.rest deleted file mode 100644 index 8e9487b8..00000000 --- a/so/META-INF/SaleRedInv.rest +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/so/src/public/nccloud/api/so/saleinvoice/operator/BillSaveAction.java b/so/src/public/nccloud/api/so/saleinvoice/operator/BillSaveAction.java deleted file mode 100644 index 2d10b235..00000000 --- a/so/src/public/nccloud/api/so/saleinvoice/operator/BillSaveAction.java +++ /dev/null @@ -1,397 +0,0 @@ -package nccloud.api.so.saleinvoice.operator; - -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import nc.bs.framework.common.NCLocator; -import nc.bs.framework.core.util.ObjectCreator; -import nc.bs.logging.Logger; -import nc.bs.trade.business.HYSuperDMO; -import nc.itf.uap.IUAPQueryBS; -import nc.jdbc.framework.processor.MapProcessor; -import nc.pubitf.so.m32.api.ISaleinvoiceQueryAPI; -import nc.vo.pub.BusinessException; -import nc.vo.pub.lang.UFBoolean; -import nc.vo.pub.lang.UFDate; -import nc.vo.pub.lang.UFDouble; -import nc.vo.pubapp.calculator.HslParseUtil; -import nc.vo.pubapp.pattern.tool.performance.DeepCloneTool; -import nc.vo.scmpub.res.billtype.SOBillType; -import nc.vo.so.m32.entity.SaleInvoiceBVO; -import nc.vo.so.m32.entity.SaleInvoiceHVO; -import nc.vo.so.m32.entity.SaleInvoiceVO; -import nc.vo.sscivm.ivsale.IVApplicationAggVO; -import nc.vo.sscivm.ivsale.IVApplicationBodyVO; -import nc.vo.sscivm.ivsale.IVApplicationHeadVO; -import nccloud.api.baseapp.exchange.convert.IExchangeForService; -import nccloud.api.baseapp.exchange.convert.OpenApiConvertDataObject; -import nccloud.api.baseapp.exchange.convert.OpenApiConvertDataResult; -import nccloud.api.rest.utils.ResultMessageUtil; -import nccloud.commons.lang.StringUtils; -import nccloud.itf.sscivm.ivsale.impl.IVApplicationServiceImpl; -import nccloud.pubitf.riart.pflow.CloudPFlowContext; -import nccloud.pubitf.riart.pflow.ICloudScriptPFlowService; -import nccloud.ws.rest.resource.AbstractNCCRestResource; -import org.json.JSONString; - -import javax.ws.rs.Consumes; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import java.util.List; -import java.util.Map; - -/** - * 销售发票红冲接口 - * - * @author lj - * @date 2025/03/14 - * @update 20250415 mzr修改 - */ -@Path("so/saleinvoice/operator") -public class BillSaveAction extends AbstractNCCRestResource { - - public static String fplxStr = "";// 开票申请发票类型 - - public static DeepCloneTool deepCloneTool; - - public static DeepCloneTool getCloneTool() { - if (deepCloneTool == null) { - deepCloneTool = new DeepCloneTool(); - } - return deepCloneTool; - } - - public BillSaveAction() { - - } - - public OpenApiConvertDataResult changeToExchangeData(OpenApiConvertDataObject openApiConvertDataObject) - throws Exception { - return getPFxxEJBService().changeToExchangeData(openApiConvertDataObject); - } - - public static IExchangeForService getPFxxEJBService() { - IExchangeForService exchangeForService = (IExchangeForService) ObjectCreator.newInstance("ufesbexpress", - "nccloud.pubimpl.pfxx.convert.ExchangeForServiceImpl"); - return exchangeForService; - } - - @Override - public String getModule() { - return "so"; - } - - @POST - @Path("/billSaveRp") - @Consumes({"application/json"}) - @Produces({"application/json"}) - public JSONString billSaveRp(JSONString json) throws Exception { - /** - * 销售发票红冲: - * 1.根据bip传参中的销售发票主表id查询erp的销售发票VO - * 2.根据查询的销售发票VO生成红冲的销售发票 - */ - JSONObject jobject = JSONObject.parseObject(json.toJSONString()); - if (jobject == null) { - return ResultMessageUtil.exceptionToJSON(new NullPointerException("JSONString:null")); - } - JSONObject bject = jobject.getJSONObject("billhead"); - if (bject == null) { - return ResultMessageUtil.exceptionToJSON(new NullPointerException("billhead:null")); - } - // 销售发票id - String csaleinvoiceid = bject.getString("vdef40"); - // 根据销售发票主实体id查询销售发票 - String[] ids = {csaleinvoiceid}; - SaleInvoiceVO[] saleInvoiceVOs = NCLocator.getInstance().lookup(ISaleinvoiceQueryAPI.class) - .queryVOByIDs(ids); - if (saleInvoiceVOs == null || saleInvoiceVOs.length <= 0) { - return ResultMessageUtil.exceptionToJSON(new NullPointerException("未在系统中查询到对应的销售发票")); - } - try { - // 调用函数根据原销售发票组装新红冲发票 - SaleInvoiceVO saleInvoiceRedRushVO = makeNewRedRushSaleInvoice(saleInvoiceVOs[0], bject); - // 生成红冲发票 - ICloudScriptPFlowService flowService = NCLocator.getInstance().lookup(ICloudScriptPFlowService.class); - CloudPFlowContext context = new CloudPFlowContext(); - context.setBillType("32"); - context.setBillVos(new SaleInvoiceVO[]{saleInvoiceRedRushVO}); - context.setActionName("WRITE"); - SaleInvoiceVO[] returnSaveSaleInvoiceVOs = (SaleInvoiceVO[]) flowService.exeScriptPFlow(context); - Logger.error("=========================inv-save============== "); - if (returnSaveSaleInvoiceVOs != null && returnSaveSaleInvoiceVOs.length > 0) { - Logger.error("inv-save = " + JSONArray.toJSONString(returnSaveSaleInvoiceVOs)); - // 生成红冲发票成功后,执行销售发票审批动作 - context.setBillType("32"); - context.setBillVos(returnSaveSaleInvoiceVOs); - context.setActionName("APPROVE"); - SaleInvoiceVO[] returnApproveSaleInvoiceVOs = (SaleInvoiceVO[]) flowService.exeScriptPFlow(context); - if (returnApproveSaleInvoiceVOs == null || returnApproveSaleInvoiceVOs.length <= 0) { - throw new BusinessException("生成销售发票审核失败"); - } - Logger.error("=========================inv-audit============== "); - Logger.error("inv-audit = " + JSONArray.toJSONString(returnApproveSaleInvoiceVOs)); - /** - * 开票申请红冲逻辑: - * 1.根据销售发票号查询下游开票申请 - * 2.根据原开票申请生成新红冲 - */ - String vBillcode = saleInvoiceVOs[0].getParentVO().getVbillcode(); - HYSuperDMO dmo = new HYSuperDMO(); - // 开票申请单主表 - IVApplicationHeadVO[] iVApplicationHeadVO = (IVApplicationHeadVO[]) dmo.queryByWhereClause(IVApplicationHeadVO.class, "src_billno='" + vBillcode + "' and dr=0 "); - String pk_ivapplication = iVApplicationHeadVO[0].getPk_ivapplication(); // 开票申请id - // 开票申请单子表 - IVApplicationBodyVO[] iVApplicationBodyVOs = (IVApplicationBodyVO[]) dmo.queryByWhereClause(IVApplicationBodyVO.class, "pk_ivapplication='" + pk_ivapplication + "' and dr=0 "); - // 调用函数封装开票申请红冲VO - IVApplicationAggVO iVApplicationAggVO = makeNewRedRushIVApplicationAggVO(iVApplicationHeadVO[0], iVApplicationBodyVOs, bject, returnApproveSaleInvoiceVOs); - // 生成红冲的开票申请 - IVApplicationServiceImpl serviceImpl = new IVApplicationServiceImpl(); - IVApplicationAggVO returnSaveIVApplicationAggVO = serviceImpl.save(iVApplicationAggVO); - if (returnSaveIVApplicationAggVO != null) { - return ResultMessageUtil.toJSON(returnApproveSaleInvoiceVOs, "接口调用成功"); - } else { - Exception e = new Exception("接口调用失败"); - return ResultMessageUtil.exceptionToJSON(e); - } - } else { - Exception e = new Exception("接口调用失败"); - return ResultMessageUtil.exceptionToJSON(e); - } - } catch (Exception e) { - Logger.error("billSaveRp-exp: ", e); - return ResultMessageUtil.exceptionToJSON(e); - } - } - - /** - * 构造红冲发票VO - * - * @param originalVO - * @param bject - * @return - * @throws Exception - */ - public static SaleInvoiceVO makeNewRedRushSaleInvoice(SaleInvoiceVO originalVO, JSONObject bject) throws Exception { - try { - SaleInvoiceVO saleInvoiceVO = new SaleInvoiceVO(); - // 发票主实体 - SaleInvoiceHVO saleInvoiceHVO = originalVO.getParentVO(); - // 发票子实体数组 - SaleInvoiceBVO[] saleInvoiceBVOs = originalVO.getChildrenVO(); - // 发票新主实体 - SaleInvoiceHVO newSaleInvoiceHVO = new SaleInvoiceHVO(); - - // 单据日期 - UFDate dbilldate = new UFDate(bject.getString("dbilldate")); - // 制单日期 - UFDate dmakedate = new UFDate(bject.getString("creationtime")); - - // 子实体属性赋值 - UFDouble sumNum = new UFDouble(); // 合计数量 - UFDouble sumNtax = new UFDouble(); // 合计税额 - UFDouble sumNcaltaxmny = new UFDouble(); // 合计计税金额 - UFDouble sumNorigmny = new UFDouble(); // 合计无税金额 - UFDouble sumNorigtaxmny = new UFDouble(); // 合计价税合计 - int i = 0; - // 参数子实体数组 - com.alibaba.fastjson.JSONArray bvoJsonArr = (com.alibaba.fastjson.JSONArray) bject.get("csaleinvoicebid"); - List bvoList = bvoJsonArr.toJavaList(JSONObject.class); - SaleInvoiceBVO[] newSaleInvoiceBVOs = new SaleInvoiceBVO[bvoList.size()]; // 新子实体 - for (SaleInvoiceBVO saleInvoiceBVO : saleInvoiceBVOs) { - String csaleinvoicebid = saleInvoiceBVO.getCsaleinvoicebid(); // 子表id - // 筛选参数红冲的子表集合 - List newBvoArr = bvoList.stream().filter(item -> { - String parCsaleinvoicebid = item.getString("vbdef15") + ""; // 子表id - return csaleinvoicebid.equals(parCsaleinvoicebid); - }).toList(); - if (newBvoArr.size() <= 0) { - continue; - } - JSONObject bipBvoJson = newBvoArr.get(0); // 参数子表 - SaleInvoiceBVO newInvBVO = new SaleInvoiceBVO(); - // 克隆取值原子表销售发票 - newInvBVO = (SaleInvoiceBVO) getCloneTool().deepClone(saleInvoiceBVO); - // 赋值之后修改子实体红冲时字段 - newInvBVO.setCsaleinvoicebid(null); // 发票子实体id - newInvBVO.setDbilldate(dbilldate); // 开票日期 - String vchangerate = "1/1"; // 换算率 - Map soMap = getSaleOrderInfo(bipBvoJson.getString("csrcbid")); - if (soMap != null && StringUtils.isNotEmpty(soMap.getOrDefault("vchangerate", "") + "")) { - vchangerate = soMap.get("vchangerate") + ""; // 销售订单的换算率 - } - newInvBVO.setVchangerate(vchangerate); // 换算率 - UFDouble[] vchangerateNums = HslParseUtil.parseHsl(vchangerate); - UFDouble vchangerateNum = UFDouble.ONE_DBL; - if (null != vchangerateNums && vchangerateNums.length != 0) { - vchangerateNum = vchangerateNums[0].div(vchangerateNums[1]).setScale(2, 4); - } - // BIP合同平台的数量对应BIP2312的主数量,BIP2312的 数量=主数量*换算关系 - UFDouble nastnum = new UFDouble(bipBvoJson.getString("nastnum")); - newInvBVO.setNastnum(nastnum.multiply(vchangerateNum).setScale(2, 4)); // 数量 - newInvBVO.setNnum(nastnum); // 主数量 - newInvBVO.setNtax(new UFDouble(bipBvoJson.getString("ntax"))); // 税额 - newInvBVO.setNmny(new UFDouble(bipBvoJson.getString("nmny"))); // 本币无税金额 - newInvBVO.setNtaxmny(new UFDouble(bipBvoJson.getString("ntaxmny"))); // 本币价税合计 - newInvBVO.setNcaltaxmny(new UFDouble(bipBvoJson.getString("ncaltaxmny"))); // 计税金额 - newInvBVO.setNorigmny(new UFDouble(bipBvoJson.getString("norigmny"))); // 无税金额 - newInvBVO.setNorigtaxmny(new UFDouble(bipBvoJson.getString("norigtaxmny"))); // 价税合计 - newInvBVO.setCopposesrcbid(bipBvoJson.getString("vbdef15")); // 对冲来源子表id - newInvBVO.setNqtunitnum(null); // 报价数量 - newInvBVO.setCsaleinvoiceid(null); // 发票关联主表id - newInvBVO.setNtotalcostnum(null); // 累计成本结算数量 - newInvBVO.setNtotalincomemny(null); // 累计确认应收金额 - newInvBVO.setNtotalincomenum(null); // 累计确认应收数量 - newSaleInvoiceBVOs[i++] = newInvBVO; - sumNum = sumNum.add(new UFDouble(bipBvoJson.getString("nnum"))); - sumNtax = sumNtax.add(new UFDouble(bipBvoJson.getString("ntax"))); - sumNcaltaxmny = sumNcaltaxmny.add(new UFDouble(bipBvoJson.getString("ncaltaxmny"))); - sumNorigmny = sumNorigmny.add(new UFDouble(bipBvoJson.getString("norigmny"))); - sumNorigtaxmny = sumNorigtaxmny.add(new UFDouble(bipBvoJson.getString("norigtaxmny"))); - } - - // 克隆取值原子表销售发票 - newSaleInvoiceHVO = (SaleInvoiceHVO) getCloneTool().deepClone(saleInvoiceHVO); - // 赋值之后修改主实体红冲时字段 - newSaleInvoiceHVO.setCsaleinvoiceid(null); // 发票主实体id - newSaleInvoiceHVO.setVbillcode(null); // 发票号 - newSaleInvoiceHVO.setDbilldate(dbilldate); // 开票日期 - newSaleInvoiceHVO.setDmakedate(dmakedate); // 制单日期 - newSaleInvoiceHVO.setBsubunitflag(UFBoolean.TRUE); // 冲抵标记 - newSaleInvoiceHVO.setFopposeflag(2); // 对冲标记 (2:对冲生成) - newSaleInvoiceHVO.setFstatusflag(1); // 单据状态 (1:自由态) - newSaleInvoiceHVO.setNtotalastnum(null); // 总数量 - newSaleInvoiceHVO.setNtotalorigsubmny(null); // 冲抵金额 - newSaleInvoiceHVO.setNtotalorigmny(null); // 价税合计 - newSaleInvoiceHVO.setVopposesrccode(saleInvoiceHVO.getVbillcode()); // 对冲来源发票号 - newSaleInvoiceHVO.setCopposesrcid(saleInvoiceHVO.getCsaleinvoiceid()); // 对冲来源发票id - newSaleInvoiceHVO.setApprover(null); // 审批人 - newSaleInvoiceHVO.setTaudittime(null); // 审批日期 - - // 组装VO - saleInvoiceVO.setParentVO(newSaleInvoiceHVO); - saleInvoiceVO.setChildrenVO(newSaleInvoiceBVOs); - return saleInvoiceVO; - } catch (Exception e) { - throw new BusinessException(e.getMessage()); - } - } - - /** - * 构造红冲开票申请VO - * - * @param applyHeadVO 原开票申请主实体 - * @param ivApplicationBodyVOS 原开票申请子实体 - * @param bject bip参数 - * @param returnApproveSaleInvoiceVOs 新生成的红冲销售发票实体 - * @return - * @throws Exception - */ - public static IVApplicationAggVO makeNewRedRushIVApplicationAggVO(IVApplicationHeadVO applyHeadVO, IVApplicationBodyVO[] ivApplicationBodyVOS, JSONObject bject, SaleInvoiceVO[] returnApproveSaleInvoiceVOs) throws Exception { - try { - IVApplicationAggVO applicationAggVO = new IVApplicationAggVO(); - IVApplicationHeadVO newivApplicationHeadVO = new IVApplicationHeadVO(); // 新主实体 - - // 取新生成红冲发票的主实体数据 - String csaleinvoiceid = returnApproveSaleInvoiceVOs[0].getParentVO().getCsaleinvoiceid(); - String[] ids = {csaleinvoiceid}; - SaleInvoiceVO[] rpSaleInvoiceVOs = NCLocator.getInstance().lookup(ISaleinvoiceQueryAPI.class) - .queryVOByIDs(ids); - SaleInvoiceHVO rpSaleInvoiceHVO = rpSaleInvoiceVOs[0].getParentVO(); - - // 主实体属性赋值 - // 克隆取值原子表开票申请 - newivApplicationHeadVO = (IVApplicationHeadVO) getCloneTool().deepClone(applyHeadVO); - // 根据参数判断是否为部分红冲 - boolean isPartHCFlag = false; - UFDouble paramNtotalorigmny = new UFDouble(bject.getString("ntotalorigmny")); // 参数价税合计(主表红冲金额) - UFDouble ntotalorigmny = applyHeadVO.getJshj(); // 原开票申请主表价税合计 - // 红冲金额与开票申请源价税合计比较如果和值大于零,则为部分红冲 - if (ntotalorigmny.add(paramNtotalorigmny).compareTo(UFDouble.ZERO_DBL) > 0) { - isPartHCFlag = true; - } - UFDouble sumXmsl = new UFDouble(); // 合计数量 - UFDouble sumXmje = new UFDouble(); // 合计金额 - UFDouble sumXmjshj = new UFDouble(); // 合计价税合计 - UFDouble sumBchcje = new UFDouble(); // 合计本次红冲金额 - UFDouble sumSe = new UFDouble(); // 合计税额 - // 子实体属性赋值 - int i = 0; - // 参数子实体数组 - com.alibaba.fastjson.JSONArray bvoJsonArr = (com.alibaba.fastjson.JSONArray) bject.get("csaleinvoicebid"); - List bvoList = bvoJsonArr.toJavaList(JSONObject.class); - IVApplicationBodyVO[] newivApplicationBodyVOS = new IVApplicationBodyVO[bvoList.size()]; // 新子实体 - for (IVApplicationBodyVO ivApplicationBodyVO : ivApplicationBodyVOS) { - String src_pkdetail = ivApplicationBodyVO.getSrc_pkdetail(); // 来源单据行id - // 筛选参数红冲的子表集合 - List newBvoArr = bvoList.stream().filter(item -> { - String parCsaleinvoicebid = item.getString("vbdef15") + ""; // 子表id - return src_pkdetail.equals(parCsaleinvoicebid); - }).toList(); - if (newBvoArr.size() <= 0) { - continue; - } - JSONObject bipBvoJson = newBvoArr.get(0); // 参数子表 - IVApplicationBodyVO newivApplicationBodyVO = new IVApplicationBodyVO(); -// BeanUtil.copyProperties(ivApplicationBodyVO,newivApplicationBodyVO, CopyOptions.create().setIgnoreNullValue(true)); - // 克隆取值原子表开票申请 - newivApplicationBodyVO = (IVApplicationBodyVO) getCloneTool().deepClone(ivApplicationBodyVO); - // 赋值之后修改子实体红冲时字段 - newivApplicationBodyVO.setPk_ivappdetail(null); // 开票申请子实体id - newivApplicationBodyVO.setBillno(null); // 开票申请子实体单据号 - newivApplicationBodyVO.setSe(new UFDouble(bipBvoJson.getString("ntax"))); // 税额 - newivApplicationBodyVO.setXmsl(new UFDouble(bipBvoJson.getString("nnum"))); // 数量 - newivApplicationBodyVO.setXmje(new UFDouble(bipBvoJson.getString("norigmny"))); // 金额 - newivApplicationBodyVO.setXmjshj(new UFDouble(bipBvoJson.getString("norigtaxmny"))); // 价税合计 - // 本次红冲金额 = 本次参数红冲金额 - newivApplicationBodyVO.setBchcje(new UFDouble(bipBvoJson.getString("norigtaxmny")).multiply(new UFDouble(-1))); - newivApplicationBodyVOS[i++] = newivApplicationBodyVO; - sumSe = sumSe.add(new UFDouble(bipBvoJson.getString("ntax"))); - sumXmsl = sumXmsl.add(new UFDouble(bipBvoJson.getString("nnum"))); - sumXmje = sumXmje.add(new UFDouble(bipBvoJson.getString("norigmny"))); - sumXmjshj = sumXmjshj.add(new UFDouble(bipBvoJson.getString("norigtaxmny"))); - sumBchcje = sumBchcje.add(new UFDouble(bipBvoJson.getString("norigtaxmny")).multiply(new UFDouble(-1))); - } - // 赋值之后修改主实体红冲时字段 - newivApplicationHeadVO.setPk_ivapplication(null); // 开票申请单主实体id - newivApplicationHeadVO.setBillno(null); // 单据号 - newivApplicationHeadVO.setPreparedate(new UFDate(bject.getString("dbilldate"))); // 单据日期 - newivApplicationHeadVO.setJshj(sumXmjshj); // 价税合计 - newivApplicationHeadVO.setHjje(sumXmje); // 合计金额 - newivApplicationHeadVO.setHjse(sumSe); // 合计税额 - newivApplicationHeadVO.setBchcje(sumBchcje); // 本次红冲金额 - newivApplicationHeadVO.setHzfp(UFBoolean.TRUE); // 红字发票 - newivApplicationHeadVO.setSrc_billtype(SOBillType.Invoice.getCode()); // 来源单据类型 - newivApplicationHeadVO.setSrc_tradetype(rpSaleInvoiceHVO.getCtrantypeid()); // 来源交易类型 - newivApplicationHeadVO.setTranstypecode(rpSaleInvoiceHVO.getVtrantypecode()); // 来源交易类型编码 - newivApplicationHeadVO.setSrc_pkbusibill(rpSaleInvoiceHVO.getCsaleinvoiceid()); // 来源单据id - newivApplicationHeadVO.setSrc_billno(rpSaleInvoiceHVO.getVbillcode()); // 来源单据编号 - newivApplicationHeadVO.setHcyy("2"); // 红冲原因:2(开票有误) - - // 组装VO - applicationAggVO.setParentVO(newivApplicationHeadVO); - applicationAggVO.setChildrenVO(newivApplicationBodyVOS); - return applicationAggVO; - } catch (Exception e) { - throw new BusinessException(e.getMessage()); - } - } - - public IUAPQueryBS getQueryService() { - return NCLocator.getInstance().lookup(IUAPQueryBS.class); - } - - - private static Map getSaleOrderInfo(String csaleorderbid) throws BusinessException { - IUAPQueryBS queryBS = NCLocator.getInstance().lookup(IUAPQueryBS.class); - String sql = " select s.vbillcode,s.csaleorderid, s.corigcurrencyid," + - " sb.csaleorderbid,sb.crowno,sb.blargessflag,sb.nexchangerate," + - " nvl(sb.vchangerate, '1/1') vchangerate, bdc.code currencycode" + - " from so_saleorder_b sb" + - " inner join so_saleorder s on sb.csaleorderid=s.csaleorderid" + - " left join bd_currtype bdc on s.corigcurrencyid=bdc.pk_currtype" + - " where sb.csaleorderbid='" + csaleorderbid + "' "; - return (Map) queryBS.executeQuery(sql, new MapProcessor()); - } - -} \ No newline at end of file diff --git a/so/src/public/nccloud/api/so/saleinvoice/operator/IAPISaleInvMaitainImpl.java b/so/src/public/nccloud/api/so/saleinvoice/operator/IAPISaleInvMaitainImpl.java new file mode 100644 index 00000000..9844d78f --- /dev/null +++ b/so/src/public/nccloud/api/so/saleinvoice/operator/IAPISaleInvMaitainImpl.java @@ -0,0 +1,645 @@ +package nccloud.api.so.saleinvoice.operator; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import nc.bs.framework.common.InvocationInfoProxy; +import nc.bs.framework.common.NCLocator; +import nc.bs.logging.Logger; +import nc.bs.trade.business.HYSuperDMO; +import nc.itf.uap.IUAPQueryBS; +import nc.jdbc.framework.processor.ColumnProcessor; +import nc.jdbc.framework.processor.MapProcessor; +import nc.pubitf.so.m32.api.ISaleinvoiceQueryAPI; +import nc.vo.pub.BusinessException; +import nc.vo.pub.lang.UFBoolean; +import nc.vo.pub.lang.UFDate; +import nc.vo.pub.lang.UFDouble; +import nc.vo.pubapp.calculator.HslParseUtil; +import nc.vo.pubapp.pattern.model.entity.bill.AbstractBill; +import nc.vo.pubapp.pattern.tool.performance.DeepCloneTool; +import nc.vo.pubapp.pflow.PfUserObject; +import nc.vo.scmpub.res.billtype.SOBillType; +import nc.vo.so.m32.entity.SaleInvoiceBVO; +import nc.vo.so.m32.entity.SaleInvoiceHVO; +import nc.vo.so.m32.entity.SaleInvoiceVO; +import nc.vo.sscivm.ivsale.IVApplicationAggVO; +import nc.vo.sscivm.ivsale.IVApplicationBodyVO; +import nc.vo.sscivm.ivsale.IVApplicationHeadVO; +import nccloud.api.baseapp.exchange.convert.OpenApiConvertDataObject; +import nccloud.api.baseapp.exchange.convert.OpenApiConvertDataResult; +import nccloud.api.rest.utils.ResultMessageUtil; +import nccloud.commons.lang.StringUtils; +import nccloud.dto.scmpub.script.entity.SCMScriptResultDTO; +import nccloud.itf.sscivm.ivsale.impl.IVApplicationServiceImpl; +import nccloud.pubitf.riart.pflow.CloudPFlowContext; +import nccloud.pubitf.riart.pflow.ICloudScriptPFlowService; +import nccloud.pubitf.scmpub.commit.service.IBatchRunScriptService; +import nccloud.pubitf.scmpub.ssc.service.ISSCService; +import nccloud.pubitf.so.saleinvoice.service.ISaleInvoiceToTaxInvService; +import nccloud.pubitf.ssctp.sscbd.lientage.ISSClientageMatchService; +import org.json.JSONString; + +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.util.List; +import java.util.Map; + +public class IAPISaleInvMaitainImpl { + + public static String fplxStr = "";// 开票申请发票类型 + + public static DeepCloneTool deepCloneTool; + + public static DeepCloneTool getCloneTool() { + if (deepCloneTool == null) { + deepCloneTool = new DeepCloneTool(); + } + return deepCloneTool; + } + + public JSONString saveBlue(JSONObject jobject) throws Exception { + JSONObject ufinterfaceObj = jsonObjectAss(jobject); + String tsType = ufinterfaceObj.getString("tsType"); + if (tsType != null && tsType.equals("1")) { + Exception e = new NullPointerException("销售订单查询关联失败!"); + return ResultMessageUtil.exceptionToJSON(e); + } + JSONObject bjects = ufinterfaceObj.getJSONObject("ufinterface"); + String billtype = bjects.getString("billtype"); + String account = bjects.getString("account"); + String omscode = bjects.getString("orgcode"); + String groupcode = bjects.getString("groupcode"); + + if (billtype != null && account != null && groupcode != null && "32".equals(billtype)) { + OpenApiConvertDataObject openApiconvertData0bject = new OpenApiConvertDataObject(); + openApiconvertData0bject.setAccount(account); + openApiconvertData0bject.setBilltype(billtype); + openApiconvertData0bject.setGroupcode(groupcode); + openApiconvertData0bject.setOpenApiJsonData(ufinterfaceObj); + + OpenApiJsonConvertToExChangeXmlService oService = new OpenApiJsonConvertToExChangeXmlService(); + OpenApiConvertDataResult r = oService.changeToExchangeData(openApiconvertData0bject); + JSONObject returnJson = r.getDesc(); + String content = ""; + // 逐层解析 JSON 数据 + JSONObject ufinterface = returnJson.getJSONObject("ufinterface"); + if (ufinterface != null) { + JSONArray sendResultArray = ufinterface.getJSONArray("sendresult"); + if (sendResultArray != null && !sendResultArray.isEmpty()) { + // 提取 content 字段 + content = sendResultArray.getJSONObject(0).getString("content"); + } + } + if (content == null || content.equals("")) { + return r != null + ? ResultMessageUtil.toJSON(r.getDesc(), "0") + : ResultMessageUtil.exceptionToJSON(new NullPointerException("未知异常")); + } + String[] ids = {content}; + SaleInvoiceVO[] saleInvoiceVO = NCLocator.getInstance().lookup(ISaleinvoiceQueryAPI.class) + .queryVOByIDs(ids); + SaleInvoiceVO saleInvoiceVO22 = saleInvoiceVO[0]; + SaleInvoiceHVO saleInvoiceHVO = saleInvoiceVO22.getParentVO(); + // 销售发票审核开始 + InvocationInfoProxy.getInstance().setUserId(saleInvoiceHVO.getApprover()); + CloudPFlowContext context = new CloudPFlowContext(); + context.setBillType("32"); + context.setBillVos(new SaleInvoiceVO[]{saleInvoiceVO[0]}); + ISSCService sscService = (ISSCService) NCLocator.getInstance().lookup(ISSCService.class); + String[] actionNames = sscService.isStartSSCWorkFlow( + (AbstractBill[]) ((AbstractBill[]) context.getBillVos()), ISSClientageMatchService.BusiUnitTypeEnum.SO); + context.setActionName("APPROVE"); + context.setTrantype("32-02"); + context.setBatch(false); + context.setBatchUserObj(new PfUserObject[]{new PfUserObject()}); + IBatchRunScriptService service = (IBatchRunScriptService) NCLocator.getInstance() + .lookup(IBatchRunScriptService.class); + SCMScriptResultDTO result = service.runBacth(context, SaleInvoiceVO.class); + // 销售发票审核结束 + ISaleInvoiceToTaxInvService invoiceService = NCLocator.getInstance() + .lookup(ISaleInvoiceToTaxInvService.class); + // 数电票(增值税专用发票)=31,数电票(普通发票)=32,数电纸质发票(机动车销售统一发票)=36,数电纸质发票(增值税专用发票)=33,数电纸质发票(普通发票)=34, + // 增值税电子普通发票=1,增值税电子专用发票=2,增值税普通发票=3,增值税专用发票=4,增值税电子普通发票(成品油)=8,成品油普通发票(卷式)=9, + // 成品油普通发票=10,成品油专用发票=11,增值税普通发票(卷式)=12,增值税专用发票(机动车)=99 + invoiceService.issueTaxInvoice(saleInvoiceVO, fplxStr); + + JSONObject desc = r.getDesc(); + if (desc != null) { + // 发票的全部信息都返回给合同平台 + desc.put("vos", saleInvoiceVO); + } + return ResultMessageUtil.toJSON(desc, "0"); + } else { + Exception e = new NullPointerException( + "billtype:" + billtype + ",account:" + account + ",groupcode:" + groupcode); + return ResultMessageUtil.exceptionToJSON(e); + } + } + + public JSONString saveRed(JSONObject jobject) throws Exception { + /** + * 销售发票红冲: + * 1.根据bip传参中的销售发票主表id查询erp的销售发票VO + * 2.根据查询的销售发票VO生成红冲的销售发票 + */ + JSONObject bject = jobject.getJSONObject("billhead"); + if (bject == null) { + return ResultMessageUtil.exceptionToJSON(new NullPointerException("billhead:null")); + } + // 销售发票id + String csaleinvoiceid = bject.getString("vdef40"); + // 根据销售发票主实体id查询销售发票 + String[] ids = {csaleinvoiceid}; + SaleInvoiceVO[] saleInvoiceVOs = NCLocator.getInstance().lookup(ISaleinvoiceQueryAPI.class) + .queryVOByIDs(ids); + if (saleInvoiceVOs == null || saleInvoiceVOs.length <= 0) { + return ResultMessageUtil.exceptionToJSON(new NullPointerException("未在系统中查询到对应的销售发票")); + } + // 调用函数根据原销售发票组装新红冲发票 + SaleInvoiceVO saleInvoiceRedRushVO = makeNewRedRushSaleInvoice(saleInvoiceVOs[0], bject); + // 生成红冲发票 + ICloudScriptPFlowService flowService = NCLocator.getInstance().lookup(ICloudScriptPFlowService.class); + CloudPFlowContext context = new CloudPFlowContext(); + context.setBillType("32"); + context.setBillVos(new SaleInvoiceVO[]{saleInvoiceRedRushVO}); + context.setActionName("WRITE"); + SaleInvoiceVO[] returnSaveSaleInvoiceVOs = (SaleInvoiceVO[]) flowService.exeScriptPFlow(context); + Logger.error("=========================inv-save============== "); + if (returnSaveSaleInvoiceVOs != null && returnSaveSaleInvoiceVOs.length > 0) { + Logger.error("inv-save = " + JSONArray.toJSONString(returnSaveSaleInvoiceVOs)); + // 生成红冲发票成功后,执行销售发票审批动作 + context.setBillType("32"); + context.setBillVos(returnSaveSaleInvoiceVOs); + context.setActionName("APPROVE"); + SaleInvoiceVO[] returnApproveSaleInvoiceVOs = (SaleInvoiceVO[]) flowService.exeScriptPFlow(context); + if (returnApproveSaleInvoiceVOs == null || returnApproveSaleInvoiceVOs.length <= 0) { + throw new BusinessException("生成销售发票审核失败"); + } + Logger.error("=========================inv-audit============== "); + Logger.error("inv-audit = " + JSONArray.toJSONString(returnApproveSaleInvoiceVOs)); + /** + * 开票申请红冲逻辑: + * 1.根据销售发票号查询下游开票申请 + * 2.根据原开票申请生成新红冲 + */ + String vBillcode = saleInvoiceVOs[0].getParentVO().getVbillcode(); + HYSuperDMO dmo = new HYSuperDMO(); + // 开票申请单主表 + IVApplicationHeadVO[] iVApplicationHeadVO = (IVApplicationHeadVO[]) dmo.queryByWhereClause(IVApplicationHeadVO.class, "src_billno='" + vBillcode + "' and dr=0 "); + String pk_ivapplication = iVApplicationHeadVO[0].getPk_ivapplication(); // 开票申请id + // 开票申请单子表 + IVApplicationBodyVO[] iVApplicationBodyVOs = (IVApplicationBodyVO[]) dmo.queryByWhereClause(IVApplicationBodyVO.class, "pk_ivapplication='" + pk_ivapplication + "' and dr=0 "); + // 调用函数封装开票申请红冲VO + IVApplicationAggVO iVApplicationAggVO = makeNewRedRushIVApplicationAggVO(iVApplicationHeadVO[0], iVApplicationBodyVOs, bject, returnApproveSaleInvoiceVOs); + // 生成红冲的开票申请 + IVApplicationServiceImpl serviceImpl = new IVApplicationServiceImpl(); + IVApplicationAggVO returnSaveIVApplicationAggVO = serviceImpl.save(iVApplicationAggVO); + if (returnSaveIVApplicationAggVO != null) { + return ResultMessageUtil.toJSON(returnApproveSaleInvoiceVOs, "接口调用成功"); + } else { + Exception e = new Exception("接口调用失败"); + return ResultMessageUtil.exceptionToJSON(e); + } + } else { + Exception e = new Exception("接口调用失败"); + return ResultMessageUtil.exceptionToJSON(e); + } + } + + public static JSONObject jsonObjectAss(JSONObject originalJson) throws Exception { + try { + // 构建目标 JSON 格式 + JSONObject resultJson = new JSONObject(); + // 添加 ufinterface 字段 + JSONObject ufinterface = new JSONObject(); + ufinterface.put("billtype", "32"); + ufinterface.put("sender", "BIP_NC"); + ufinterface.put("level", "0"); + ufinterface.put("replace", "Y"); + ufinterface.put("roottag", "bill"); + ufinterface.put("isexchange", "Y"); + ufinterface.put("account", "01"); + ufinterface.put("groupcode", "00"); + // 处理 bill 数组 + JSONArray billArray = new JSONArray(); + JSONObject bill = new JSONObject(); + // billhead 结构 + JSONObject billhead = new JSONObject(); + billhead = originalJson.getJSONObject("billhead");// 传入JSON对象 + billhead.put("pk_org_v", originalJson.getJSONObject("billhead").getString("pk_org"));// 开票组织版本=开票组织 + billhead.put("pk_group", "00");// 集团 + fplxStr = originalJson.getJSONObject("billhead").getString("vdef22"); + billhead.put("vtrantypecode", "32-02");// 发票类型编码 + billhead.put("cbiztypeid", "SO01");// 业务流程 + billhead.put("approver", "BIP");// 审批人 + billhead.put("fstatusflag", 1);// 单据状态 + billhead.put("billmaker", "BIP");// 制单人 + billhead.put("csendcountryid", "CN");// 发货国家 + billhead.put("crececountryid", "CN");// 收货国家 + billhead.put("ctaxcountryid", "CN");// 报税国家 + // 2025-2-8付业要求修改,根据发票类型Q(自定义档案)对照发票类型 + String ctrantypeidStr = "32-02";// 默认普通发票 + if (fplxStr != null && fplxStr.equals("31")) { + ctrantypeidStr = "32-01";// 数电票(增值税专用发票) + } else if (fplxStr != null && fplxStr.equals("32")) { + ctrantypeidStr = "32-02";// 数电票(普通发票) + } else if (fplxStr != null && fplxStr.equals("36")) { + ctrantypeidStr = "32-Cxx-03";// 机动车销售发票 + } + billhead.put("ctrantypeid", ctrantypeidStr);// 发票类型 + // billhead.put("ctrantypeid", "32-02");//发票类型 + billhead.put("fbuysellflag", "1");// 购销类型 + billhead.put("creator", "BIP");// 创建人 + billhead.put("ccurrencyid", "CNY");// 本位币 + billhead.put("corigcurrencyid", "CNY");// 币种 + billhead.put("nexchangerate", 1);// 折本汇率 + billhead.put("btriatradeflag", 0);// 三角贸易 + JSONObject newItem = new JSONObject(); + JSONObject otherJson = new JSONObject(); + JSONArray csaleinvoicebid = new JSONArray(); + // 遍历原始数据中的 csaleinvoicebid 数组 + for (int i = 0; i < originalJson.getJSONObject("billhead").getJSONArray("csaleinvoicebid").size(); i++) { + JSONObject item = originalJson.getJSONObject("billhead").getJSONArray("csaleinvoicebid") + .getJSONObject(i); + + JSONObject itemDetails = new JSONObject(); + itemDetails = item; + itemDetails.put("carorgid", originalJson.getJSONObject("billhead").getString("pk_org"));// 应收组织 + itemDetails.put("csendstockorgid", originalJson.getJSONObject("billhead").getString("pk_org"));// 库存组织原始版本 + itemDetails.put("cmaterialid", item.getString("cmaterialvid"));// 物料编码 + Map value2 = getSaleorderVo(item.getString("csrcbid")); + if (value2 == null) { + resultJson = new JSONObject(); + resultJson.put("tsType", "1"); + return resultJson; + } + itemDetails.put("vfirsttype", "30");// 源头单据类型 + itemDetails.put("vfirstcode", value2.get("vbillcode"));// 源头单据号 + itemDetails.put("blargessflag", value2.get("blargessflag"));// 赠品 + itemDetails.put("vfirsttrantype", "30-01");// 源头交易类型 + itemDetails.put("vfirstrowno", value2.get("crowno"));// 源头单据行号 + itemDetails.put("cfirstid", item.getString("csrcid"));// 源头单据主表 + itemDetails.put("cfirstbid", item.getString("csrcbid"));// 源头单据子表 + itemDetails.put("vsrctype", "30");// 来源单据类型 + itemDetails.put("vsrccode", value2.get("vbillcode"));// 来源单据号 + itemDetails.put("vsrctrantype", "30-01");// 来源交易类型 + itemDetails.put("vsrcrowno", value2.get("crowno"));// 来源单据行号 + // 通过 ntaxrate 获取 taxcode + String taxcodeStr = getTaxcode(item.getString("ntaxrate")); + // 将 taxcodeStr 放入 bodyMap + itemDetails.put("ctaxcodeid", taxcodeStr);// 税码 + itemDetails.put("nnum", item.getString("nastnum"));// 主数量 + itemDetails.put("ftaxtypeflag", 1);// 扣税类别 + itemDetails.put("pk_group", "00");// 集团 + itemDetails.put("pk_org", originalJson.getJSONObject("billhead").getString("pk_org"));// 开票组织 + itemDetails.put("cunitid", item.getString("castunitid"));// 主单位 + itemDetails.put("vchangerate", value2.getOrDefault("vchangerate", "1/1") + "");// 换算率 + + // 从销售订单中获取币种 + String currencycode = getString_TrimAsNull(value2.get("currencycode")); + otherJson.put("corigcurrencyid", currencycode.isEmpty() ? "CNY" : currencycode); + // 从销售订单中获取折本汇率 + BigDecimal nexchangerate = getUFDouble_NullAsZero(value2.get("nexchangerate")).toBigDecimal(); + otherJson.put("nexchangerate", nexchangerate); + + // 输入参数:从你的 item 获取各个字段 + BigDecimal nastnum = new BigDecimal(item.getString("nastnum")); // 数量 + nastnum = nastnum.setScale(4, RoundingMode.HALF_UP); + BigDecimal nqtorigtaxprice = new BigDecimal(item.getString("nqtorigtaxprice")); // 含税单价 + nqtorigtaxprice = nqtorigtaxprice.setScale(4, RoundingMode.HALF_UP); + BigDecimal ntaxrate = new BigDecimal(item.getString("ntaxrate")).divide(new BigDecimal("100")); // 税率 + ntaxrate = ntaxrate.setScale(4, RoundingMode.HALF_UP); + + // 含税净价 + BigDecimal norigtaxnetprice = nqtorigtaxprice; + // 1. 计算价税合计(含税金额) + BigDecimal norigtaxmny = nastnum.multiply(norigtaxnetprice).setScale(2, RoundingMode.HALF_UP); + // 2. 计算折扣额 + BigDecimal discountAmount = nastnum.multiply(nqtorigtaxprice).subtract(norigtaxmny).setScale(4, + RoundingMode.HALF_UP); + // 3. 计算税额(两种方法:应税外加税和应税内含税) + BigDecimal ntax = norigtaxmny.multiply(ntaxrate).divide(BigDecimal.ONE.add(ntaxrate), 2, + RoundingMode.HALF_UP); // 应税外加税 + BigDecimal taxInclusiveInner = norigtaxmny.multiply(ntaxrate).setScale(4, RoundingMode.HALF_UP); // 应税内含税 + // 4. 计算无税金额 + BigDecimal norigmny = norigtaxmny.subtract(ntax).setScale(2, RoundingMode.HALF_UP); + // 4. 计算无税单价(nqtorigprice = 无税金额 / 数量) + BigDecimal nqtorigprice = norigmny.divide(nastnum, 4, RoundingMode.HALF_UP); + // 计税金额 = 无税金额 + BigDecimal ncaltaxmny = norigmny; + // 主含税单价(即含税单价) + BigDecimal norigtaxprice = nqtorigtaxprice.setScale(4, RoundingMode.HALF_UP); + // 主无税净价(即不含税单价) + BigDecimal norignetprice = nqtorigprice; + + // 本币(人民币)需要处理汇率,金额保留两位小数,单价保留4位小数 + // 本币无税金额 + BigDecimal nmny = norigmny.multiply(nexchangerate).setScale(2, RoundingMode.HALF_UP); + // 主本币无税净价 + BigDecimal nnetprice = norignetprice.multiply(nexchangerate).setScale(4, RoundingMode.HALF_UP); + // 本币价税合计 价税合计*汇率 + BigDecimal ntaxmny = norigtaxmny.multiply(nexchangerate).setScale(2, RoundingMode.HALF_UP); + // 税额 + ntax = ntaxmny.subtract(nmny).setScale(2, RoundingMode.HALF_UP); + + itemDetails.put("nqtorigprice", nqtorigprice);// 无税单价 + itemDetails.put("norigprice", nqtorigprice);// 主无税单价 + itemDetails.put("norigmny", norigmny);// 无税金额 + itemDetails.put("nmny", nmny);// 本币无税金额 + itemDetails.put("norigtaxmny", norigtaxmny);// 价税合计 + itemDetails.put("norigtaxprice", norigtaxprice);// 主含税单价 + itemDetails.put("norignetprice", norignetprice);// 主无税净价 + itemDetails.put("nqtorigtaxprice", nqtorigtaxprice);// 含税单价 + itemDetails.put("ntax", ntax);// 税额 + itemDetails.put("ncaltaxmny", ncaltaxmny);// 计税金额 + itemDetails.put("norigtaxnetprice", norigtaxnetprice);// 主含税净价 + itemDetails.put("nnetprice", nnetprice);// 主本币无税净价 + itemDetails.put("ntaxmny", ntaxmny);// 本币价税合计 + csaleinvoicebid.add(itemDetails); + + } + newItem.put("item", csaleinvoicebid); + billhead.put("csaleinvoicebid", newItem); + if (otherJson != null && !otherJson.isEmpty()) { + // 查询销售订单中的币种和汇率 + billhead.put("corigcurrencyid", otherJson.get("corigcurrencyid"));// 币种 + billhead.put("nexchangerate", otherJson.get("nexchangerate"));// 折本汇率 + } + bill.put("billhead", billhead); + bill.put("id", ""); + // 将 bill 数组添加到 ufinterface 中 + billArray.add(bill); + ufinterface.put("bill", billArray); + // 将 ufinterface 添加到最终的 resultJson 中 + resultJson.put("ufinterface", ufinterface); + return resultJson; + } catch (Exception e) { + return (JSONObject) ResultMessageUtil.exceptionToJSON(e); + } + } + + private static String getTaxcode(String taxrateStr) throws BusinessException { + IUAPQueryBS queryBS = NCLocator.getInstance().lookup(IUAPQueryBS.class); + String sql = " select code FROM bd_taxrate tt inner join bd_taxcode tc on tt.pk_taxcode=tc.pk_taxcode where taxrate='" + + taxrateStr + "' AND ROWNUM = 1 "; + String taxcodeStr = (String) queryBS.executeQuery(sql, new ColumnProcessor()); + return taxcodeStr; + } + + private static Map getSaleorderVo(String csourcebillbidStr) throws BusinessException { + IUAPQueryBS queryBS = NCLocator.getInstance().lookup(IUAPQueryBS.class); + String sql = " select s.vbillcode,s.csaleorderid, s.corigcurrencyid," + + " sb.csaleorderbid,sb.crowno,sb.blargessflag,sb.nexchangerate,sb.vchangerate," + + " bdc.code currencycode" + + " from so_saleorder_b sb" + + " inner join so_saleorder s on sb.csaleorderid=s.csaleorderid" + + " left join bd_currtype bdc on s.corigcurrencyid=bdc.pk_currtype" + + " where sb.csaleorderbid='" + csourcebillbidStr + "' "; + Map value2 = (Map) queryBS.executeQuery(sql, new MapProcessor()); + return value2; + } + + private static String getString_TrimAsNull(Object value) { + if ((value == null) || (value.toString().trim().isEmpty())) { + return ""; + } + return value.toString().trim(); + } + + private static UFDouble getUFDouble_NullAsZero(Object value) { + if ((value == null) || (value.toString().trim().isEmpty()) || (value.toString().trim().equals("~"))) + return UFDouble.ONE_DBL; + if ((value instanceof UFDouble)) + return (UFDouble) value; + if ((value instanceof BigDecimal)) { + return new UFDouble((BigDecimal) value); + } + return new UFDouble(value.toString().trim()); + } + + /** + * 构造红冲发票VO + * + * @param originalVO + * @param bject + * @return + * @throws Exception + */ + public static SaleInvoiceVO makeNewRedRushSaleInvoice(SaleInvoiceVO originalVO, JSONObject bject) throws Exception { + try { + SaleInvoiceVO saleInvoiceVO = new SaleInvoiceVO(); + // 发票主实体 + SaleInvoiceHVO saleInvoiceHVO = originalVO.getParentVO(); + // 发票子实体数组 + SaleInvoiceBVO[] saleInvoiceBVOs = originalVO.getChildrenVO(); + // 发票新主实体 + SaleInvoiceHVO newSaleInvoiceHVO = new SaleInvoiceHVO(); + + // 单据日期 + UFDate dbilldate = new UFDate(bject.getString("dbilldate")); + // 制单日期 + UFDate dmakedate = new UFDate(bject.getString("creationtime")); + + // 子实体属性赋值 + UFDouble sumNum = new UFDouble(); // 合计数量 + UFDouble sumNtax = new UFDouble(); // 合计税额 + UFDouble sumNcaltaxmny = new UFDouble(); // 合计计税金额 + UFDouble sumNorigmny = new UFDouble(); // 合计无税金额 + UFDouble sumNorigtaxmny = new UFDouble(); // 合计价税合计 + int i = 0; + // 参数子实体数组 + com.alibaba.fastjson.JSONArray bvoJsonArr = (com.alibaba.fastjson.JSONArray) bject.get("csaleinvoicebid"); + List bvoList = bvoJsonArr.toJavaList(JSONObject.class); + SaleInvoiceBVO[] newSaleInvoiceBVOs = new SaleInvoiceBVO[bvoList.size()]; // 新子实体 + for (SaleInvoiceBVO saleInvoiceBVO : saleInvoiceBVOs) { + String csaleinvoicebid = saleInvoiceBVO.getCsaleinvoicebid(); // 子表id + // 筛选参数红冲的子表集合 + List newBvoArr = bvoList.stream().filter(item -> { + String parCsaleinvoicebid = item.getString("vbdef15") + ""; // 子表id + return csaleinvoicebid.equals(parCsaleinvoicebid); + }).toList(); + if (newBvoArr.size() <= 0) { + continue; + } + JSONObject bipBvoJson = newBvoArr.get(0); // 参数子表 + SaleInvoiceBVO newInvBVO = new SaleInvoiceBVO(); + // 克隆取值原子表销售发票 + newInvBVO = (SaleInvoiceBVO) getCloneTool().deepClone(saleInvoiceBVO); + // 赋值之后修改子实体红冲时字段 + newInvBVO.setCsaleinvoicebid(null); // 发票子实体id + newInvBVO.setDbilldate(dbilldate); // 开票日期 + String vchangerate = "1/1"; // 换算率 + Map soMap = getSaleOrderInfo(bipBvoJson.getString("csrcbid")); + if (soMap != null && StringUtils.isNotEmpty(soMap.getOrDefault("vchangerate", "") + "")) { + vchangerate = soMap.get("vchangerate") + ""; // 销售订单的换算率 + } + newInvBVO.setVchangerate(vchangerate); // 换算率 + UFDouble[] vchangerateNums = HslParseUtil.parseHsl(vchangerate); + UFDouble vchangerateNum = UFDouble.ONE_DBL; + if (null != vchangerateNums && vchangerateNums.length != 0) { + vchangerateNum = vchangerateNums[0].div(vchangerateNums[1]).setScale(2, 4); + } + // BIP合同平台的数量对应BIP2312的主数量,BIP2312的 数量=主数量*换算关系 + UFDouble nastnum = new UFDouble(bipBvoJson.getString("nastnum")); + newInvBVO.setNastnum(nastnum.multiply(vchangerateNum).setScale(2, 4)); // 数量 + newInvBVO.setNnum(nastnum); // 主数量 + newInvBVO.setNtax(new UFDouble(bipBvoJson.getString("ntax"))); // 税额 + newInvBVO.setNmny(new UFDouble(bipBvoJson.getString("nmny"))); // 本币无税金额 + newInvBVO.setNtaxmny(new UFDouble(bipBvoJson.getString("ntaxmny"))); // 本币价税合计 + newInvBVO.setNcaltaxmny(new UFDouble(bipBvoJson.getString("ncaltaxmny"))); // 计税金额 + newInvBVO.setNorigmny(new UFDouble(bipBvoJson.getString("norigmny"))); // 无税金额 + newInvBVO.setNorigtaxmny(new UFDouble(bipBvoJson.getString("norigtaxmny"))); // 价税合计 + newInvBVO.setCopposesrcbid(bipBvoJson.getString("vbdef15")); // 对冲来源子表id + newInvBVO.setNqtunitnum(null); // 报价数量 + newInvBVO.setCsaleinvoiceid(null); // 发票关联主表id + newInvBVO.setNtotalcostnum(null); // 累计成本结算数量 + newInvBVO.setNtotalincomemny(null); // 累计确认应收金额 + newInvBVO.setNtotalincomenum(null); // 累计确认应收数量 + newSaleInvoiceBVOs[i++] = newInvBVO; + sumNum = sumNum.add(new UFDouble(bipBvoJson.getString("nnum"))); + sumNtax = sumNtax.add(new UFDouble(bipBvoJson.getString("ntax"))); + sumNcaltaxmny = sumNcaltaxmny.add(new UFDouble(bipBvoJson.getString("ncaltaxmny"))); + sumNorigmny = sumNorigmny.add(new UFDouble(bipBvoJson.getString("norigmny"))); + sumNorigtaxmny = sumNorigtaxmny.add(new UFDouble(bipBvoJson.getString("norigtaxmny"))); + } + + // 克隆取值原子表销售发票 + newSaleInvoiceHVO = (SaleInvoiceHVO) getCloneTool().deepClone(saleInvoiceHVO); + // 赋值之后修改主实体红冲时字段 + newSaleInvoiceHVO.setCsaleinvoiceid(null); // 发票主实体id + newSaleInvoiceHVO.setVbillcode(null); // 发票号 + newSaleInvoiceHVO.setDbilldate(dbilldate); // 开票日期 + newSaleInvoiceHVO.setDmakedate(dmakedate); // 制单日期 + newSaleInvoiceHVO.setBsubunitflag(UFBoolean.TRUE); // 冲抵标记 + newSaleInvoiceHVO.setFopposeflag(2); // 对冲标记 (2:对冲生成) + newSaleInvoiceHVO.setFstatusflag(1); // 单据状态 (1:自由态) + newSaleInvoiceHVO.setNtotalastnum(null); // 总数量 + newSaleInvoiceHVO.setNtotalorigsubmny(null); // 冲抵金额 + newSaleInvoiceHVO.setNtotalorigmny(null); // 价税合计 + newSaleInvoiceHVO.setVopposesrccode(saleInvoiceHVO.getVbillcode()); // 对冲来源发票号 + newSaleInvoiceHVO.setCopposesrcid(saleInvoiceHVO.getCsaleinvoiceid()); // 对冲来源发票id + newSaleInvoiceHVO.setApprover(null); // 审批人 + newSaleInvoiceHVO.setTaudittime(null); // 审批日期 + + // 组装VO + saleInvoiceVO.setParentVO(newSaleInvoiceHVO); + saleInvoiceVO.setChildrenVO(newSaleInvoiceBVOs); + return saleInvoiceVO; + } catch (Exception e) { + throw new BusinessException(e.getMessage()); + } + } + + /** + * 构造红冲开票申请VO + * + * @param applyHeadVO 原开票申请主实体 + * @param ivApplicationBodyVOS 原开票申请子实体 + * @param bject bip参数 + * @param returnApproveSaleInvoiceVOs 新生成的红冲销售发票实体 + * @return + * @throws Exception + */ + public static IVApplicationAggVO makeNewRedRushIVApplicationAggVO(IVApplicationHeadVO applyHeadVO, IVApplicationBodyVO[] ivApplicationBodyVOS, JSONObject bject, SaleInvoiceVO[] returnApproveSaleInvoiceVOs) throws Exception { + try { + IVApplicationAggVO applicationAggVO = new IVApplicationAggVO(); + IVApplicationHeadVO newivApplicationHeadVO = new IVApplicationHeadVO(); // 新主实体 + + // 取新生成红冲发票的主实体数据 + String csaleinvoiceid = returnApproveSaleInvoiceVOs[0].getParentVO().getCsaleinvoiceid(); + String[] ids = {csaleinvoiceid}; + SaleInvoiceVO[] rpSaleInvoiceVOs = NCLocator.getInstance().lookup(ISaleinvoiceQueryAPI.class) + .queryVOByIDs(ids); + SaleInvoiceHVO rpSaleInvoiceHVO = rpSaleInvoiceVOs[0].getParentVO(); + + // 主实体属性赋值 + // 克隆取值原子表开票申请 + newivApplicationHeadVO = (IVApplicationHeadVO) getCloneTool().deepClone(applyHeadVO); + // 根据参数判断是否为部分红冲 + boolean isPartHCFlag = false; + UFDouble paramNtotalorigmny = new UFDouble(bject.getString("ntotalorigmny")); // 参数价税合计(主表红冲金额) + UFDouble ntotalorigmny = applyHeadVO.getJshj(); // 原开票申请主表价税合计 + // 红冲金额与开票申请源价税合计比较如果和值大于零,则为部分红冲 + if (ntotalorigmny.add(paramNtotalorigmny).compareTo(UFDouble.ZERO_DBL) > 0) { + isPartHCFlag = true; + } + UFDouble sumXmsl = new UFDouble(); // 合计数量 + UFDouble sumXmje = new UFDouble(); // 合计金额 + UFDouble sumXmjshj = new UFDouble(); // 合计价税合计 + UFDouble sumBchcje = new UFDouble(); // 合计本次红冲金额 + UFDouble sumSe = new UFDouble(); // 合计税额 + // 子实体属性赋值 + int i = 0; + // 参数子实体数组 + com.alibaba.fastjson.JSONArray bvoJsonArr = (com.alibaba.fastjson.JSONArray) bject.get("csaleinvoicebid"); + List bvoList = bvoJsonArr.toJavaList(JSONObject.class); + IVApplicationBodyVO[] newivApplicationBodyVOS = new IVApplicationBodyVO[bvoList.size()]; // 新子实体 + for (IVApplicationBodyVO ivApplicationBodyVO : ivApplicationBodyVOS) { + String src_pkdetail = ivApplicationBodyVO.getSrc_pkdetail(); // 来源单据行id + // 筛选参数红冲的子表集合 + List newBvoArr = bvoList.stream().filter(item -> { + String parCsaleinvoicebid = item.getString("vbdef15") + ""; // 子表id + return src_pkdetail.equals(parCsaleinvoicebid); + }).toList(); + if (newBvoArr.size() <= 0) { + continue; + } + JSONObject bipBvoJson = newBvoArr.get(0); // 参数子表 + IVApplicationBodyVO newivApplicationBodyVO = new IVApplicationBodyVO(); +// BeanUtil.copyProperties(ivApplicationBodyVO,newivApplicationBodyVO, CopyOptions.create().setIgnoreNullValue(true)); + // 克隆取值原子表开票申请 + newivApplicationBodyVO = (IVApplicationBodyVO) getCloneTool().deepClone(ivApplicationBodyVO); + // 赋值之后修改子实体红冲时字段 + newivApplicationBodyVO.setPk_ivappdetail(null); // 开票申请子实体id + newivApplicationBodyVO.setBillno(null); // 开票申请子实体单据号 + newivApplicationBodyVO.setSe(new UFDouble(bipBvoJson.getString("ntax"))); // 税额 + newivApplicationBodyVO.setXmsl(new UFDouble(bipBvoJson.getString("nnum"))); // 数量 + newivApplicationBodyVO.setXmje(new UFDouble(bipBvoJson.getString("norigmny"))); // 金额 + newivApplicationBodyVO.setXmjshj(new UFDouble(bipBvoJson.getString("norigtaxmny"))); // 价税合计 + // 本次红冲金额 = 本次参数红冲金额 + newivApplicationBodyVO.setBchcje(new UFDouble(bipBvoJson.getString("norigtaxmny")).multiply(new UFDouble(-1))); + newivApplicationBodyVOS[i++] = newivApplicationBodyVO; + sumSe = sumSe.add(new UFDouble(bipBvoJson.getString("ntax"))); + sumXmsl = sumXmsl.add(new UFDouble(bipBvoJson.getString("nnum"))); + sumXmje = sumXmje.add(new UFDouble(bipBvoJson.getString("norigmny"))); + sumXmjshj = sumXmjshj.add(new UFDouble(bipBvoJson.getString("norigtaxmny"))); + sumBchcje = sumBchcje.add(new UFDouble(bipBvoJson.getString("norigtaxmny")).multiply(new UFDouble(-1))); + } + // 赋值之后修改主实体红冲时字段 + newivApplicationHeadVO.setPk_ivapplication(null); // 开票申请单主实体id + newivApplicationHeadVO.setBillno(null); // 单据号 + newivApplicationHeadVO.setPreparedate(new UFDate(bject.getString("dbilldate"))); // 单据日期 + newivApplicationHeadVO.setJshj(sumXmjshj); // 价税合计 + newivApplicationHeadVO.setHjje(sumXmje); // 合计金额 + newivApplicationHeadVO.setHjse(sumSe); // 合计税额 + newivApplicationHeadVO.setBchcje(sumBchcje); // 本次红冲金额 + newivApplicationHeadVO.setHzfp(UFBoolean.TRUE); // 红字发票 + newivApplicationHeadVO.setSrc_billtype(SOBillType.Invoice.getCode()); // 来源单据类型 + newivApplicationHeadVO.setSrc_tradetype(rpSaleInvoiceHVO.getCtrantypeid()); // 来源交易类型 + newivApplicationHeadVO.setTranstypecode(rpSaleInvoiceHVO.getVtrantypecode()); // 来源交易类型编码 + newivApplicationHeadVO.setSrc_pkbusibill(rpSaleInvoiceHVO.getCsaleinvoiceid()); // 来源单据id + newivApplicationHeadVO.setSrc_billno(rpSaleInvoiceHVO.getVbillcode()); // 来源单据编号 + newivApplicationHeadVO.setHcyy("2"); // 红冲原因:2(开票有误) + + // 组装VO + applicationAggVO.setParentVO(newivApplicationHeadVO); + applicationAggVO.setChildrenVO(newivApplicationBodyVOS); + return applicationAggVO; + } catch (Exception e) { + throw new BusinessException(e.getMessage()); + } + } + + private static Map getSaleOrderInfo(String csaleorderbid) throws BusinessException { + IUAPQueryBS queryBS = NCLocator.getInstance().lookup(IUAPQueryBS.class); + String sql = " select s.vbillcode,s.csaleorderid, s.corigcurrencyid," + + " sb.csaleorderbid,sb.crowno,sb.blargessflag,sb.nexchangerate," + + " nvl(sb.vchangerate, '1/1') vchangerate, bdc.code currencycode" + + " from so_saleorder_b sb" + + " inner join so_saleorder s on sb.csaleorderid=s.csaleorderid" + + " left join bd_currtype bdc on s.corigcurrencyid=bdc.pk_currtype" + + " where sb.csaleorderbid='" + csaleorderbid + "' "; + return (Map) queryBS.executeQuery(sql, new MapProcessor()); + } + +} diff --git a/so/src/public/nccloud/api/so/saleinvoice/operator/SaleInvResource.java b/so/src/public/nccloud/api/so/saleinvoice/operator/SaleInvResource.java new file mode 100644 index 00000000..be925c78 --- /dev/null +++ b/so/src/public/nccloud/api/so/saleinvoice/operator/SaleInvResource.java @@ -0,0 +1,76 @@ +package nccloud.api.so.saleinvoice.operator; + +import com.alibaba.fastjson.JSONObject; +import nc.bs.logging.Logger; +import nccloud.api.rest.utils.ResultMessageUtil; +import nccloud.ws.rest.resource.AbstractNCCRestResource; +import org.json.JSONString; + +import javax.ws.rs.Consumes; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +/** + * 销售发票接口适配2005代码 + * zhangxinah + */ +@Path("so/saleinvoice/operator") +public class SaleInvResource extends AbstractNCCRestResource { + + public SaleInvResource() { + } + + @Override + public String getModule() { + return "so"; + } + + @POST + @Path("saveCommit") + @Consumes({"application/json"}) + @Produces({"application/json"}) + public JSONString saveCommit(JSONString json) { + try { + JSONObject jobject = JSONObject.parseObject(json.toJSONString()); + if (jobject == null) { + return ResultMessageUtil.exceptionToJSON(new NullPointerException("JSONString:null")); + } + JSONObject bject = jobject.getJSONObject("billhead"); + if (bject == null) { + return ResultMessageUtil.exceptionToJSON(new NullPointerException("billhead:null")); + } + IAPISaleInvMaitainImpl service = new IAPISaleInvMaitainImpl(); + return service.saveBlue(jobject); + } catch (Exception e) { + Logger.error("saveCommit-exp: ", e); + return ResultMessageUtil.exceptionToJSON(e); + } + } + + /** + * 销售发票红冲接口 + * + * @author lj + * @date 2025/03/14 + * @update 20250415 mzr修改 + */ + @POST + @Path("billSaveRp") + @Consumes({"application/json"}) + @Produces({"application/json"}) + public JSONString billSaveRp(JSONString json) { + try { + JSONObject jobject = JSONObject.parseObject(json.toJSONString()); + if (jobject == null) { + return ResultMessageUtil.exceptionToJSON(new NullPointerException("JSONString:null")); + } + IAPISaleInvMaitainImpl service = new IAPISaleInvMaitainImpl(); + return service.saveRed(jobject); + } catch (Exception e) { + Logger.error("billSaveRp-exp: ", e); + return ResultMessageUtil.exceptionToJSON(e); + } + } + +} \ No newline at end of file diff --git a/so/src/public/nccloud/api/so/saleinvoice/operator/saveCommitAction.java b/so/src/public/nccloud/api/so/saleinvoice/operator/saveCommitAction.java deleted file mode 100644 index b721579e..00000000 --- a/so/src/public/nccloud/api/so/saleinvoice/operator/saveCommitAction.java +++ /dev/null @@ -1,431 +0,0 @@ -package nccloud.api.so.saleinvoice.operator; - -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import nc.bs.framework.common.InvocationInfoProxy; -import nc.bs.framework.common.NCLocator; -import nc.bs.framework.core.util.ObjectCreator; -import nc.itf.uap.IUAPQueryBS; -import nc.jdbc.framework.processor.ColumnProcessor; -import nc.jdbc.framework.processor.MapProcessor; -import nc.pubitf.so.m32.api.ISaleinvoiceQueryAPI; -import nc.vo.pub.BusinessException; -import nc.vo.pub.lang.UFDouble; -import nc.vo.pubapp.pattern.model.entity.bill.AbstractBill; -import nc.vo.pubapp.pflow.PfUserObject; -import nc.vo.so.m32.entity.SaleInvoiceHVO; -import nc.vo.so.m32.entity.SaleInvoiceVO; -import nccloud.api.baseapp.exchange.convert.IExchangeForService; -import nccloud.api.baseapp.exchange.convert.OpenApiConvertDataObject; -import nccloud.api.baseapp.exchange.convert.OpenApiConvertDataResult; -import nccloud.api.rest.utils.ResultMessageUtil; -import nccloud.dto.scmpub.script.entity.SCMScriptResultDTO; -import nccloud.pubitf.riart.pflow.CloudPFlowContext; -import nccloud.pubitf.scmpub.commit.service.IBatchRunScriptService; -import nccloud.pubitf.scmpub.ssc.service.ISSCService; -import nccloud.pubitf.so.saleinvoice.service.ISaleInvoiceToTaxInvService; -import nccloud.pubitf.ssctp.sscbd.lientage.ISSClientageMatchService.BusiUnitTypeEnum; -import nccloud.ws.rest.resource.AbstractNCCRestResource; -import org.json.JSONString; - -import javax.ws.rs.Consumes; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import java.math.BigDecimal; -import java.math.RoundingMode; -import java.util.Map; - -/** - * 销售发票接口适配2005代码 - * zhangxinah - */ -@Path("so/saleinvoice/operator") -public class saveCommitAction extends AbstractNCCRestResource { - - public static String fplxStr = "";// 开票申请发票类型 - - public saveCommitAction() { - - } - - public OpenApiConvertDataResult changeToExchangeData(OpenApiConvertDataObject openApiConvertDataObject) - throws Exception { - return getPFxxEJBService().changeToExchangeData(openApiConvertDataObject); - } - - public static IExchangeForService getPFxxEJBService() { - IExchangeForService exchangeForService = (IExchangeForService) ObjectCreator.newInstance("ufesbexpress", - "nccloud.pubimpl.pfxx.convert.ExchangeForServiceImpl"); - return exchangeForService; - } - - @Override - public String getModule() { - return "so"; - } - - @POST - @Path("/saveCommit") - @Consumes({"application/json"}) - @Produces({"application/json"}) - public JSONString saveCommit(JSONString json) throws Exception { - JSONObject jobject = JSONObject.parseObject(json.toJSONString()); - if (jobject == null) { - return ResultMessageUtil.exceptionToJSON(new NullPointerException("JSONString:null")); - } else { - JSONObject bject = jobject.getJSONObject("billhead"); - if (bject == null) { - return ResultMessageUtil.exceptionToJSON(new NullPointerException("billhead:null")); - } else { - - JSONObject ufinterfaceObj = jsonObjectAss(jobject); - String tsType = ufinterfaceObj.getString("tsType"); - if (tsType != null && tsType.equals("1")) { - Exception e = new NullPointerException("销售订单查询关联失败!"); - return ResultMessageUtil.exceptionToJSON(e); - } - JSONObject bjects = ufinterfaceObj.getJSONObject("ufinterface"); - String billtype = bjects.getString("billtype"); - String account = bjects.getString("account"); - String omscode = bjects.getString("orgcode"); - String groupcode = bjects.getString("groupcode"); - - if (billtype != null && account != null && groupcode != null && "32".equals(billtype)) { - OpenApiConvertDataObject openApiconvertData0bject = new OpenApiConvertDataObject(); - openApiconvertData0bject.setAccount(account); - openApiconvertData0bject.setBilltype(billtype); - openApiconvertData0bject.setGroupcode(groupcode); - openApiconvertData0bject.setOpenApiJsonData(ufinterfaceObj); - try { - OpenApiJsonConvertToExChangeXmlService oService = new OpenApiJsonConvertToExChangeXmlService(); - OpenApiConvertDataResult r = oService.changeToExchangeData(openApiconvertData0bject); - JSONObject returnJson = r.getDesc(); - String content = ""; - // 逐层解析 JSON 数据 - JSONObject ufinterface = returnJson.getJSONObject("ufinterface"); - if (ufinterface != null) { - JSONArray sendResultArray = ufinterface.getJSONArray("sendresult"); - if (sendResultArray != null && sendResultArray.size() > 0) { - // 提取 content 字段 - content = sendResultArray.getJSONObject(0).getString("content"); - } - } - if (content == null || content.equals("")) { - return r != null ? ResultMessageUtil.toJSON(r.getDesc(), "0") - : ResultMessageUtil.exceptionToJSON(new NullPointerException("未知异常")); - } - String[] ids = {content}; - SaleInvoiceVO[] saleInvoiceVO = NCLocator.getInstance().lookup(ISaleinvoiceQueryAPI.class) - .queryVOByIDs(ids); - SaleInvoiceVO saleInvoiceVO22 = saleInvoiceVO[0]; - SaleInvoiceHVO saleInvoiceHVO = saleInvoiceVO22.getParentVO(); - // 销售发票审核开始 - InvocationInfoProxy.getInstance().setUserId(saleInvoiceHVO.getApprover()); - CloudPFlowContext context = new CloudPFlowContext(); - context.setBillType("32"); - context.setBillVos(new SaleInvoiceVO[]{saleInvoiceVO[0]}); - ISSCService sscService = (ISSCService) NCLocator.getInstance().lookup(ISSCService.class); - String[] actionNames = sscService.isStartSSCWorkFlow( - (AbstractBill[]) ((AbstractBill[]) context.getBillVos()), BusiUnitTypeEnum.SO); - context.setActionName("APPROVE"); - context.setTrantype("32-02"); - context.setBatch(false); - context.setBatchUserObj(new PfUserObject[]{new PfUserObject()}); - IBatchRunScriptService service = (IBatchRunScriptService) NCLocator.getInstance() - .lookup(IBatchRunScriptService.class); - SCMScriptResultDTO result = service.runBacth(context, SaleInvoiceVO.class); - // 销售发票审核结束 - ISaleInvoiceToTaxInvService invoiceService = NCLocator.getInstance() - .lookup(ISaleInvoiceToTaxInvService.class); - // 数电票(增值税专用发票)=31,数电票(普通发票)=32,数电纸质发票(机动车销售统一发票)=36,数电纸质发票(增值税专用发票)=33,数电纸质发票(普通发票)=34, - // 增值税电子普通发票=1,增值税电子专用发票=2,增值税普通发票=3,增值税专用发票=4,增值税电子普通发票(成品油)=8,成品油普通发票(卷式)=9, - // 成品油普通发票=10,成品油专用发票=11,增值税普通发票(卷式)=12,增值税专用发票(机动车)=99 - invoiceService.issueTaxInvoice(saleInvoiceVO, fplxStr); - - JSONObject desc = r.getDesc(); - if (desc != null) { - // 发票的全部信息都返回给合同平台 - desc.put("vos", saleInvoiceVO); - } - return ResultMessageUtil.toJSON(desc, "0"); - } catch (Exception e) { - return ResultMessageUtil.exceptionToJSON(e); - } - } else { - Exception e = new NullPointerException( - "billtype:" + billtype + ",account:" + account + ",groupcode:" + groupcode); - return ResultMessageUtil.exceptionToJSON(e); - } - - } - } - } - - public static JSONObject jsonObjectAss(JSONObject originalJson) throws Exception { - try { - // 构建目标 JSON 格式 - JSONObject resultJson = new JSONObject(); - // 添加 ufinterface 字段 - JSONObject ufinterface = new JSONObject(); - ufinterface.put("billtype", "32"); - ufinterface.put("sender", "BIP_NC"); - ufinterface.put("level", "0"); - ufinterface.put("replace", "Y"); - ufinterface.put("roottag", "bill"); - ufinterface.put("isexchange", "Y"); - ufinterface.put("account", "01"); - ufinterface.put("groupcode", "00"); - // 处理 bill 数组 - JSONArray billArray = new JSONArray(); - JSONObject bill = new JSONObject(); - // billhead 结构 - JSONObject billhead = new JSONObject(); - billhead = originalJson.getJSONObject("billhead");// 传入JSON对象 - billhead.put("pk_org_v", originalJson.getJSONObject("billhead").getString("pk_org"));// 开票组织版本=开票组织 - billhead.put("pk_group", "00");// 集团 - fplxStr = originalJson.getJSONObject("billhead").getString("vdef22"); - billhead.put("vtrantypecode", "32-02");// 发票类型编码 - billhead.put("cbiztypeid", "SO01");// 业务流程 - billhead.put("approver", "BIP");// 审批人 - billhead.put("fstatusflag", 1);// 单据状态 - billhead.put("billmaker", "BIP");// 制单人 - billhead.put("csendcountryid", "CN");// 发货国家 - billhead.put("crececountryid", "CN");// 收货国家 - billhead.put("ctaxcountryid", "CN");// 报税国家 - // 2025-2-8付业要求修改,根据发票类型Q(自定义档案)对照发票类型 - String ctrantypeidStr = "32-02";// 默认普通发票 - if (fplxStr != null && fplxStr.equals("31")) { - ctrantypeidStr = "32-01";// 数电票(增值税专用发票) - } else if (fplxStr != null && fplxStr.equals("32")) { - ctrantypeidStr = "32-02";// 数电票(普通发票) - } else if (fplxStr != null && fplxStr.equals("36")) { - ctrantypeidStr = "32-Cxx-03";// 机动车销售发票 - } - billhead.put("ctrantypeid", ctrantypeidStr);// 发票类型 - // billhead.put("ctrantypeid", "32-02");//发票类型 - billhead.put("fbuysellflag", "1");// 购销类型 - billhead.put("creator", "BIP");// 创建人 - billhead.put("ccurrencyid", "CNY");// 本位币 - billhead.put("corigcurrencyid", "CNY");// 币种 - billhead.put("nexchangerate", 1);// 折本汇率 - billhead.put("btriatradeflag", 0);// 三角贸易 - JSONObject newItem = new JSONObject(); - JSONObject otherJson = new JSONObject(); - JSONArray csaleinvoicebid = new JSONArray(); - // 遍历原始数据中的 csaleinvoicebid 数组 - for (int i = 0; i < originalJson.getJSONObject("billhead").getJSONArray("csaleinvoicebid").size(); i++) { - JSONObject item = originalJson.getJSONObject("billhead").getJSONArray("csaleinvoicebid") - .getJSONObject(i); - - JSONObject itemDetails = new JSONObject(); - itemDetails = item; - itemDetails.put("carorgid", originalJson.getJSONObject("billhead").getString("pk_org"));// 应收组织 - itemDetails.put("csendstockorgid", originalJson.getJSONObject("billhead").getString("pk_org"));// 库存组织原始版本 - itemDetails.put("cmaterialid", item.getString("cmaterialvid"));// 物料编码 - Map value2 = getSaleorderVo(item.getString("csrcbid")); - if (value2 == null) { - resultJson = new JSONObject(); - resultJson.put("tsType", "1"); - return resultJson; - } - itemDetails.put("vfirsttype", "30");// 源头单据类型 - itemDetails.put("vfirstcode", value2.get("vbillcode"));// 源头单据号 - itemDetails.put("blargessflag", value2.get("blargessflag"));// 赠品 - itemDetails.put("vfirsttrantype", "30-01");// 源头交易类型 - itemDetails.put("vfirstrowno", value2.get("crowno"));// 源头单据行号 - itemDetails.put("cfirstid", item.getString("csrcid"));// 源头单据主表 - itemDetails.put("cfirstbid", item.getString("csrcbid"));// 源头单据子表 - itemDetails.put("vsrctype", "30");// 来源单据类型 - itemDetails.put("vsrccode", value2.get("vbillcode"));// 来源单据号 - itemDetails.put("vsrctrantype", "30-01");// 来源交易类型 - itemDetails.put("vsrcrowno", value2.get("crowno"));// 来源单据行号 - // 通过 ntaxrate 获取 taxcode - String taxcodeStr = getTaxcode(item.getString("ntaxrate")); - // 将 taxcodeStr 放入 bodyMap - itemDetails.put("ctaxcodeid", taxcodeStr);// 税码 - itemDetails.put("nnum", item.getString("nastnum"));// 主数量 - itemDetails.put("ftaxtypeflag", 1);// 扣税类别 - itemDetails.put("pk_group", "00");// 集团 - itemDetails.put("pk_org", originalJson.getJSONObject("billhead").getString("pk_org"));// 开票组织 - itemDetails.put("cunitid", item.getString("castunitid"));// 主单位 - itemDetails.put("vchangerate", value2.getOrDefault("vchangerate", "1/1") + "");// 换算率 - -// double nastnum = Double.parseDouble(item.getString("nastnum"));//数量 -// double nqtorigtaxprice = Double.parseDouble(item.getString("nqtorigtaxprice"));//含税单价 -// double ntaxrate = Double.parseDouble(item.getString("ntaxrate"));//税率 -// -// double nqtorigprice = -// Math.round(nqtorigtaxprice / (1 + ntaxrate) * 100.0) / 100.0;//不含税单价、无税单价(含税单价/(1+税率)) -// double norigmny = Math.round(nqtorigprice * nastnum * 100.0) / 100.0;//无税金额(不含税单价*数量) -// double norigtaxmny = Math.round(nastnum * nqtorigtaxprice * 100.0) / 100.0;//价税合计、含税金额(数量*含税单价) -// double norigtaxprice = Math.round(nqtorigtaxprice * 100.0) / 100.0;//主含税单价(含税单价) -// double norignetprice = nqtorigprice;//主无税净价(不含税单价) -// double ntax = Math.round(norigtaxmny / (1 + ntaxrate) * ntaxrate * 100.0) / 100.0;//税额(含税金额/(1+税率)*税率) -// double ncaltaxmny = norigmny;//计税金额(无税金额) -// double norigtaxnetprice = norigtaxprice;//主含税净价(主含税单价) - -// BigDecimal nastnum = new BigDecimal(item.getString("nastnum"));//数量 -// BigDecimal nqtorigtaxprice = new BigDecimal(item.getString("nqtorigtaxprice"));//含税单价 -// BigDecimal ntaxrate = new BigDecimal(item.getString("ntaxrate"));//税率 -// -// // 1. 计算不含税单价 -// BigDecimal nqtorigprice = nqtorigtaxprice.divide(BigDecimal.ONE.add(ntaxrate), 4, RoundingMode.HALF_UP); -// // 2. 计算无税金额 = 不含税单价 * 数量 -// BigDecimal norigmny = nqtorigprice.multiply(nastnum).setScale(4, RoundingMode.HALF_UP); -// // 3. 计算税额 = 无税金额 * 税率 -// BigDecimal ntax = norigmny.multiply(ntaxrate).setScale(4, RoundingMode.HALF_UP); -// // 4. 计算含税金额 = 无税金额 + 税额 -// BigDecimal norigtaxmny = norigmny.add(ntax).setScale(4, RoundingMode.HALF_UP); -// // 主含税单价(即含税单价) -// BigDecimal norigtaxprice = nqtorigtaxprice.setScale(4, RoundingMode.HALF_UP); -// // 主无税净价(即不含税单价) -// BigDecimal norignetprice = nqtorigprice; -// // 计税金额 = 无税金额 -// BigDecimal ncaltaxmny = norigmny; -// // 主含税净价 = 含税单价(原始) -// BigDecimal norigtaxnetprice = norigtaxprice; - - // 从销售订单中获取币种 - String currencycode = getString_TrimAsNull(value2.get("currencycode")); - otherJson.put("corigcurrencyid", currencycode.isEmpty() ? "CNY" : currencycode); - // 从销售订单中获取折本汇率 - BigDecimal nexchangerate = getUFDouble_NullAsZero(value2.get("nexchangerate")).toBigDecimal(); - otherJson.put("nexchangerate", nexchangerate); - - // 输入参数:从你的 item 获取各个字段 - BigDecimal nastnum = new BigDecimal(item.getString("nastnum")); // 数量 - nastnum = nastnum.setScale(4, RoundingMode.HALF_UP); - BigDecimal nqtorigtaxprice = new BigDecimal(item.getString("nqtorigtaxprice")); // 含税单价 - nqtorigtaxprice = nqtorigtaxprice.setScale(4, RoundingMode.HALF_UP); - BigDecimal ntaxrate = new BigDecimal(item.getString("ntaxrate")).divide(new BigDecimal("100")); // 税率 - ntaxrate = ntaxrate.setScale(4, RoundingMode.HALF_UP); - - // 含税净价 - BigDecimal norigtaxnetprice = nqtorigtaxprice; - // 1. 计算价税合计(含税金额) - BigDecimal norigtaxmny = nastnum.multiply(norigtaxnetprice).setScale(2, RoundingMode.HALF_UP); - // 2. 计算折扣额 - BigDecimal discountAmount = nastnum.multiply(nqtorigtaxprice).subtract(norigtaxmny).setScale(4, - RoundingMode.HALF_UP); - // 3. 计算税额(两种方法:应税外加税和应税内含税) - BigDecimal ntax = norigtaxmny.multiply(ntaxrate).divide(BigDecimal.ONE.add(ntaxrate), 2, - RoundingMode.HALF_UP); // 应税外加税 - BigDecimal taxInclusiveInner = norigtaxmny.multiply(ntaxrate).setScale(4, RoundingMode.HALF_UP); // 应税内含税 - // 4. 计算无税金额 - BigDecimal norigmny = norigtaxmny.subtract(ntax).setScale(2, RoundingMode.HALF_UP); - // 4. 计算无税单价(nqtorigprice = 无税金额 / 数量) - BigDecimal nqtorigprice = norigmny.divide(nastnum, 4, RoundingMode.HALF_UP); - // 计税金额 = 无税金额 - BigDecimal ncaltaxmny = norigmny; - // 主含税单价(即含税单价) - BigDecimal norigtaxprice = nqtorigtaxprice.setScale(4, RoundingMode.HALF_UP); - // 主无税净价(即不含税单价) - BigDecimal norignetprice = nqtorigprice; - - // 本币(人民币)需要处理汇率,金额保留两位小数,单价保留4位小数 - // 本币无税金额 - BigDecimal nmny = norigmny.multiply(nexchangerate).setScale(2, RoundingMode.HALF_UP); - // 主本币无税净价 - BigDecimal nnetprice = norignetprice.multiply(nexchangerate).setScale(4, RoundingMode.HALF_UP); - // 本币价税合计 价税合计*汇率 - BigDecimal ntaxmny = norigtaxmny.multiply(nexchangerate).setScale(2, RoundingMode.HALF_UP); - // 税额 - ntax = ntaxmny.subtract(nmny).setScale(2, RoundingMode.HALF_UP); - - itemDetails.put("nqtorigprice", nqtorigprice);// 无税单价 - itemDetails.put("norigprice", nqtorigprice);// 主无税单价 - itemDetails.put("norigmny", norigmny);// 无税金额 - itemDetails.put("nmny", nmny);// 本币无税金额 - itemDetails.put("norigtaxmny", norigtaxmny);// 价税合计 - itemDetails.put("norigtaxprice", norigtaxprice);// 主含税单价 - itemDetails.put("norignetprice", norignetprice);// 主无税净价 - itemDetails.put("nqtorigtaxprice", nqtorigtaxprice);// 含税单价 - itemDetails.put("ntax", ntax);// 税额 - itemDetails.put("ncaltaxmny", ncaltaxmny);// 计税金额 - itemDetails.put("norigtaxnetprice", norigtaxnetprice);// 主含税净价 - itemDetails.put("nnetprice", nnetprice);// 主本币无税净价 - itemDetails.put("ntaxmny", ntaxmny);// 本币价税合计 - csaleinvoicebid.add(itemDetails); - - } - newItem.put("item", csaleinvoicebid); - billhead.put("csaleinvoicebid", newItem); - if (otherJson != null && !otherJson.isEmpty()) { - // 查询销售订单中的币种和汇率 - billhead.put("corigcurrencyid", otherJson.get("corigcurrencyid"));// 币种 - billhead.put("nexchangerate", otherJson.get("nexchangerate"));// 折本汇率 - } - bill.put("billhead", billhead); - bill.put("id", ""); - // 将 bill 数组添加到 ufinterface 中 - billArray.add(bill); - ufinterface.put("bill", billArray); - // 将 ufinterface 添加到最终的 resultJson 中 - resultJson.put("ufinterface", ufinterface); - return resultJson; - } catch (Exception e) { - return (JSONObject) ResultMessageUtil.exceptionToJSON(e); - } - } - - // 方法:检查必填项并返回转化后的Map - public static String checkRequiredFields(JSONObject data) throws Exception { - String returnStr = ""; - // 2. 检查必填字段 pk_org - String pkOrg = (String) data.getOrDefault("pk_org", ""); - if (pkOrg.isEmpty()) { - return "字段pk_org缺失或为空!"; - } - // 2. 检查必填字段 pk_org - String vbillcode = (String) data.getOrDefault("vbillcode", ""); - if (vbillcode.isEmpty()) { - return "字段vbillcode缺失或为空!"; - } - return returnStr; - } - - private static String getTaxcode(String taxrateStr) throws BusinessException { - IUAPQueryBS queryBS = NCLocator.getInstance().lookup(IUAPQueryBS.class); - String sql = " select code FROM bd_taxrate tt inner join bd_taxcode tc on tt.pk_taxcode=tc.pk_taxcode where taxrate='" - + taxrateStr + "' AND ROWNUM = 1 "; - String taxcodeStr = (String) queryBS.executeQuery(sql, new ColumnProcessor()); - return taxcodeStr; - } - - private static Map getSaleorderVo(String csourcebillbidStr) throws BusinessException { - IUAPQueryBS queryBS = NCLocator.getInstance().lookup(IUAPQueryBS.class); - String sql = " select s.vbillcode,s.csaleorderid, s.corigcurrencyid," + - " sb.csaleorderbid,sb.crowno,sb.blargessflag,sb.nexchangerate,sb.vchangerate," + - " bdc.code currencycode" + - " from so_saleorder_b sb" + - " inner join so_saleorder s on sb.csaleorderid=s.csaleorderid" + - " left join bd_currtype bdc on s.corigcurrencyid=bdc.pk_currtype" + - " where sb.csaleorderbid='" + csourcebillbidStr + "' "; - Map value2 = (Map) queryBS.executeQuery(sql, new MapProcessor()); - return value2; - } - - private static String getString_TrimAsNull(Object value) { - if ((value == null) || (value.toString().trim().isEmpty())) { - return ""; - } - return value.toString().trim(); - } - - private static UFDouble getUFDouble_NullAsZero(Object value) { - if ((value == null) || (value.toString().trim().isEmpty()) || (value.toString().trim().equals("~"))) - return UFDouble.ONE_DBL; - if ((value instanceof UFDouble)) - return (UFDouble) value; - if ((value instanceof BigDecimal)) { - return new UFDouble((BigDecimal) value); - } - return new UFDouble(value.toString().trim()); - } - - public IUAPQueryBS getQueryService() { - return NCLocator.getInstance().lookup(IUAPQueryBS.class); - } - -} \ No newline at end of file From 939614c2e2c616b418696cc6cc11a449abf9df92 Mon Sep 17 00:00:00 2001 From: "zhangxinah@yonyou.com" Date: Thu, 17 Apr 2025 15:46:07 +0800 Subject: [PATCH 08/11] =?UTF-8?q?=E7=BC=96=E7=A0=81=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E8=BD=AC=E4=B8=BAGBK?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GatheringbillEditSaveBatchBSAction.java | 156 +++++++++--------- .../GatheringbillSaveBatchBSAction.java | 18 +- 2 files changed, 89 insertions(+), 85 deletions(-) diff --git a/arap/src/private/nc/bs/arap/actions/GatheringbillEditSaveBatchBSAction.java b/arap/src/private/nc/bs/arap/actions/GatheringbillEditSaveBatchBSAction.java index 5bf8ae84..92e08e1f 100644 --- a/arap/src/private/nc/bs/arap/actions/GatheringbillEditSaveBatchBSAction.java +++ b/arap/src/private/nc/bs/arap/actions/GatheringbillEditSaveBatchBSAction.java @@ -22,89 +22,93 @@ import nc.vo.pub.lang.UFDouble; import java.util.Map; public class GatheringbillEditSaveBatchBSAction extends BillUpdateBatchBSAction { - public GatheringbillEditSaveBatchBSAction() { - this.validatorCode.add(5); - this.validatorCode.add(34); - this.validatorCode.add(57); - this.validatorCode.add(59); - this.validatorCode.add(62); - this.validatorCode.add(93); - this.validatorCode.add(94); - this.validatorCode.add(100); - this.validatorCode.remove(44); - } + public GatheringbillEditSaveBatchBSAction() { + this.validatorCode.add(5); + this.validatorCode.add(34); + this.validatorCode.add(57); + this.validatorCode.add(59); + this.validatorCode.add(62); + this.validatorCode.add(93); + this.validatorCode.add(94); + this.validatorCode.add(100); + this.validatorCode.remove(44); + } - protected void doBeforeUpdate(AggregatedValueObject[] bills, AggregatedValueObject[] orginBills) throws BusinessException { - ArapBillPubUtil.fillTradeTypeInfo(bills); + protected void doBeforeUpdate(AggregatedValueObject[] bills, AggregatedValueObject[] orginBills) + throws BusinessException { + ArapBillPubUtil.fillTradeTypeInfo(bills); - for(AggregatedValueObject bill : bills) { - ArapBillPubUtil.processMoneyOnlySum(bill); - } + for (AggregatedValueObject bill : bills) { + ArapBillPubUtil.processMoneyOnlySum(bill); + } - /** - * 鏀舵鍗曚繚瀛樻牎楠屽叧鑱旂殑閿鍞鍗曞疄闄呮敹娆鹃噾棰濇槸鍚﹁秴杩囦环绋庡悎璁 - */ - int i = 0; + /** + * 收款单保存校验关联的销售订单实际收款金额是否超过价税合计 + */ + int i = 0; - for(AggregatedValueObject bill : bills) { - AggregatedValueObject oriBill = orginBills[i++]; - BaseBillVO billVO = (BaseBillVO) bill.getParentVO(); //淇敼鐨勬敹娆惧崟 - BaseBillVO billOriVO = (BaseBillVO) oriBill.getParentVO(); //涔嬪墠鐨勬敹娆惧崟 - UFDouble money = billVO.getMoney(); //淇敼鍚庣殑閲戦 - UFDouble oriMoney = billOriVO.getMoney(); //淇敼鍓嶇殑閲戦 - String pk_tradetype = billVO.getPk_tradetype(); - if(!"F2-Cxx-02".equals(pk_tradetype)){ - continue; - } - String def3 = billVO.getDef3(); //鏀舵鍗曞搴旂殑閿鍞鍗昳d - if(StringUtil.isEmpty(def3) || "N".equals(def3) || "~".equals(def3)){ - //鏃犵粦瀹氱殑閿鍞鍗曞垯涓嬩竴娆″惊鐜 - continue; - } - //璁$畻鏀舵鍗曢噾棰濆樊鍊 - UFDouble changeMoney = money.sub(oriMoney); - //鏍规嵁閿鍞鍗昳d鍘绘煡璇㈤攢鍞鍗 - BaseDAO dao = new BaseDAO(); - String sql = "select nreceivedmny,ntotalorigmny from so_saleorder where dr = 0 and csaleorderid = '" +def3+"'"; - Map saleMap = (Map)dao.executeQuery(sql, new MapProcessor()); - //閿鍞鍗曚环绋庡悎璁 - UFDouble ntotalorigmny = UFDouble.ZERO_DBL; - //閿鍞鍗曞疄闄呮敹娆鹃噾棰 - UFDouble nreceivedmny = UFDouble.ZERO_DBL; - if(saleMap != null) { - nreceivedmny = new UFDouble(saleMap.get("nreceivedmny") == null ? "0" : saleMap.get("nreceivedmny").toString()); - ntotalorigmny = new UFDouble(saleMap.get("ntotalorigmny") == null ? "0" : saleMap.get("ntotalorigmny").toString()); - } - UFDouble moreMoney = nreceivedmny.add(changeMoney).sub(ntotalorigmny); - if(nreceivedmny.add(changeMoney).compareTo(ntotalorigmny) > 0){ - throw new BusinessException("銆愯绗旀敹娆惧凡瓒呴攢鍞鍗"+ moreMoney +"鍏冿紝鏃犳硶浼犺緭锛佽妫鏌ヨ鍗曠疮璁℃敹娆鹃噾棰濓紒銆"); - } - } + for (AggregatedValueObject bill : bills) { + AggregatedValueObject oriBill = orginBills[i++]; + BaseBillVO billVO = (BaseBillVO) bill.getParentVO(); // 修改的收款单 + BaseBillVO billOriVO = (BaseBillVO) oriBill.getParentVO(); // 之前的收款单 + UFDouble money = billVO.getMoney(); // 修改后的金额 + UFDouble oriMoney = billOriVO.getMoney(); // 修改前的金额 + String pk_tradetype = billVO.getPk_tradetype(); + if (!"F2-Cxx-02".equals(pk_tradetype)) { + continue; + } + String def3 = billVO.getDef3(); // 收款单对应的销售订单id + if (StringUtil.isEmpty(def3) || "N".equals(def3) || "~".equals(def3)) { + // 无绑定的销售订单则下一次循环 + continue; + } + // 计算收款单金额差值 + UFDouble changeMoney = money.sub(oriMoney); + // 根据销售订单id去查询销售订单 + BaseDAO dao = new BaseDAO(); + String sql = "select nreceivedmny,ntotalorigmny from so_saleorder where dr = 0 and csaleorderid = '" + def3 + + "'"; + Map saleMap = (Map) dao.executeQuery(sql, new MapProcessor()); + // 销售订单价税合计 + UFDouble ntotalorigmny = UFDouble.ZERO_DBL; + // 销售订单实际收款金额 + UFDouble nreceivedmny = UFDouble.ZERO_DBL; + if (saleMap != null) { + nreceivedmny = new UFDouble( + saleMap.get("nreceivedmny") == null ? "0" : saleMap.get("nreceivedmny").toString()); + ntotalorigmny = new UFDouble( + saleMap.get("ntotalorigmny") == null ? "0" : saleMap.get("ntotalorigmny").toString()); + } + UFDouble moreMoney = nreceivedmny.add(changeMoney).sub(ntotalorigmny); + if (nreceivedmny.add(changeMoney).compareTo(ntotalorigmny) > 0) { + throw new BusinessException("【该笔收款已超销售订单" + moreMoney + "元,无法传输!请检查订单累计收款金额!】"); + } + } - ArapBillVOUtils.prepareDefaultInfo(bills, true); - BillDateUtils.setBillDateByNow(bills); - int updateType = this.getUpdateType(bills, orginBills); + ArapBillVOUtils.prepareDefaultInfo(bills, true); + BillDateUtils.setBillDateByNow(bills); + int updateType = this.getUpdateType(bills, orginBills); - for(AggregatedValueObject bill : bills) { - bill.getParentVO().setStatus(1); - } + for (AggregatedValueObject bill : bills) { + bill.getParentVO().setStatus(1); + } - if (updateType == TEMP_2_SAVE || updateType == SAVE_2_SAVE) { - for(AggregatedValueObject bill : bills) { - for(CircularlyAccessibleValueObject item : bill.getChildrenVO()) { - if (item.getStatus() != 2 && item.getStatus() != 3) { - item.setStatus(1); - } - } - } - } + if (updateType == TEMP_2_SAVE || updateType == SAVE_2_SAVE) { + for (AggregatedValueObject bill : bills) { + for (CircularlyAccessibleValueObject item : bill.getChildrenVO()) { + if (item.getStatus() != 2 && item.getStatus() != 3) { + item.setStatus(1); + } + } + } + } - if (updateType == TEMP_2_SAVE || updateType == SAVE_2_SAVE) { - BillAccountCalendarUtils.setAccperiodYearMonth(bills); - } + if (updateType == TEMP_2_SAVE || updateType == SAVE_2_SAVE) { + BillAccountCalendarUtils.setAccperiodYearMonth(bills); + } - this.checkIsCorrdBillMoneyControl(bills, orginBills); - this.checkOtherSystemBill(bills, orginBills); - (new CrossRuleCheckValidator()).validate(bills); - } + this.checkIsCorrdBillMoneyControl(bills, orginBills); + this.checkOtherSystemBill(bills, orginBills); + (new CrossRuleCheckValidator()).validate(bills); + } } diff --git a/arap/src/private/nc/bs/arap/actions/GatheringbillSaveBatchBSAction.java b/arap/src/private/nc/bs/arap/actions/GatheringbillSaveBatchBSAction.java index 70c8334d..fd55a8b9 100644 --- a/arap/src/private/nc/bs/arap/actions/GatheringbillSaveBatchBSAction.java +++ b/arap/src/private/nc/bs/arap/actions/GatheringbillSaveBatchBSAction.java @@ -59,29 +59,29 @@ public class GatheringbillSaveBatchBSAction extends BillInsertBatchBSAction { ArapBillVOUtils.setDefaultSettleFlag(bills); /** - * 鏀舵鍗曚繚瀛樻牎楠屽叧鑱旂殑閿鍞鍗曞疄闄呮敹娆鹃噾棰濇槸鍚﹁秴杩囦环绋庡悎璁 + * 收款单保存校验关联的销售订单实际收款金额是否超过价税合计 */ for(AggregatedValueObject bill : bills) { - BaseBillVO billVO = (BaseBillVO) bill.getParentVO(); //淇敼鐨勬敹娆惧崟 - UFDouble money = billVO.getMoney(); //閲戦 + BaseBillVO billVO = (BaseBillVO) bill.getParentVO(); //修改的收款单 + UFDouble money = billVO.getMoney(); //金额 String pk_tradetype = billVO.getPk_tradetype(); if(!"F2-Cxx-02".equals(pk_tradetype)){ continue; } - String def3 = billVO.getDef3(); //鏀舵鍗曞搴旂殑閿鍞鍗昳d + String def3 = billVO.getDef3(); //收款单对应的销售订单id if(StringUtil.isEmpty(def3) || "N".equals(def3) || "~".equals(def3)){ - //鏃犵粦瀹氱殑閿鍞鍗曞垯涓嬩竴娆″惊鐜 + //无绑定的销售订单则下一次循环 continue; } - //鏍规嵁閿鍞鍗昳d鍘绘煡璇㈤攢鍞鍗 + //根据销售订单id去查询销售订单 BaseDAO dao = new BaseDAO(); String sql = "select nreceivedmny,ntotalorigmny from so_saleorder where dr = 0 and csaleorderid = '" +def3+"'"; Map saleMap = (Map)dao.executeQuery(sql, new MapProcessor()); - //閿鍞鍗曚环绋庡悎璁 + //销售订单价税合计 UFDouble ntotalorigmny = UFDouble.ZERO_DBL; - //閿鍞鍗曞疄闄呮敹娆鹃噾棰 + //销售订单实际收款金额 UFDouble nreceivedmny = UFDouble.ZERO_DBL; if(saleMap != null) { nreceivedmny = new UFDouble(saleMap.get("nreceivedmny") == null ? "0" : saleMap.get("nreceivedmny").toString()); @@ -89,7 +89,7 @@ public class GatheringbillSaveBatchBSAction extends BillInsertBatchBSAction { } UFDouble moreMoney = nreceivedmny.add(money).sub(ntotalorigmny); if(nreceivedmny.add(money).compareTo(ntotalorigmny) > 0){ - throw new BusinessException("銆愯绗旀敹娆惧凡瓒呴攢鍞鍗"+ moreMoney +"鍏冿紝鏃犳硶浼犺緭锛佽妫鏌ヨ鍗曠疮璁℃敹娆鹃噾棰濓紒銆"); + throw new BusinessException("【该笔收款已超销售订单"+ moreMoney +"元,无法传输!请检查订单累计收款金额!】"); } } } From ce12efdb62d03815bee7bf3307e9a156d9b1e528 Mon Sep 17 00:00:00 2001 From: mzr Date: Thu, 17 Apr 2025 16:39:02 +0800 Subject: [PATCH 09/11] =?UTF-8?q?=E6=9C=80=E6=96=B0=E4=BB=B7=E6=A0=BC?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E5=A2=9E=E5=8A=A0=E7=89=A9=E6=96=99=E5=A4=87?= =?UTF-8?q?=E6=B3=A8=E6=9F=A5=E8=AF=A2=E6=9D=A1=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../supplierprice/rule/SupPriceQryRule.java | 34 +++++++++++++------ .../nc/vo/pp/report/util/PurpRptUtils.java | 20 ++++++++--- 2 files changed, 39 insertions(+), 15 deletions(-) diff --git a/purp/src/private/nc/impl/pp/supplierprice/rule/SupPriceQryRule.java b/purp/src/private/nc/impl/pp/supplierprice/rule/SupPriceQryRule.java index bcaed470..081dd3a2 100644 --- a/purp/src/private/nc/impl/pp/supplierprice/rule/SupPriceQryRule.java +++ b/purp/src/private/nc/impl/pp/supplierprice/rule/SupPriceQryRule.java @@ -82,7 +82,7 @@ public class SupPriceQryRule { return ""; } else { ConditionVO[] copyconvos = (ConditionVO[])CloneUtil.deepClone(convos); - + List list = new ArrayList(); for(ConditionVO vo : copyconvos) { if (vo.getFieldCode().equals(SupPriceRptConst.DBUSINESSDATE)) { int month = Integer.valueOf(vo.getValue()); @@ -91,17 +91,23 @@ public class SupPriceQryRule { vo.setFieldCode(htablealias + ".dbilldate"); vo.setOperaCode("between"); vo.setDataType(3); - String var10001 = befdate.toString(); - vo.setValue(var10001 + " ," + curdate.toString() + " "); + String befdateStr = befdate.toString(); + vo.setValue(befdateStr + " ," + curdate.toString() + " "); } else if (vo.getFieldCode().equals("pk_supplier")) { vo.setFieldCode(htablealias + ".cvendorid"); + } else if (vo.getFieldCode().equalsIgnoreCase("memo")) { + tranMap.put("memo", vo); } else { vo.setFieldCode(htablealias + "." + vo.getFieldCode()); } + if (!vo.getFieldCode().equalsIgnoreCase("memo")) { + list.add(vo); + } } StringBuilder sql = new StringBuilder(""); - sql.append((new ConditionVO()).getSQLStr(copyconvos)); + ConditionVO[] array = list.toArray(new ConditionVO[0]); + sql.append((new ConditionVO()).getSQLStr(array)); this.addMarWhere(sql, tranMap, rptutils, btablealias); return sql.toString(); } @@ -162,9 +168,11 @@ public class SupPriceQryRule { vo.setFieldCode(htablealias + ".dbilldate"); vo.setOperaCode("between"); vo.setDataType(3); - String var10001 = befdate.toString(); - vo.setValue(var10001 + " ," + curdate.toString() + " "); + String befdateStr = befdate.toString(); + vo.setValue(befdateStr + " ," + curdate.toString() + " "); list.add(vo); + } else if (vo.getFieldCode().equalsIgnoreCase("memo")) { + tranMap.put("memo", vo); } else if (!vo.getFieldCode().equals("bsc")) { vo.setFieldCode(htablealias + "." + vo.getFieldCode()); list.add(vo); @@ -184,7 +192,7 @@ public class SupPriceQryRule { return ""; } else { ConditionVO[] copyconvos = (ConditionVO[])CloneUtil.deepClone(convos); - + List list = new ArrayList(); for(ConditionVO vo : copyconvos) { if (vo.getFieldCode().equals(SupPriceRptConst.DBUSINESSDATE)) { int month = Integer.valueOf(vo.getValue()); @@ -193,19 +201,25 @@ public class SupPriceQryRule { vo.setFieldCode(tablealias + ".dvaliddate"); vo.setOperaCode("between"); vo.setDataType(3); - String var10001 = befdate.toString(); - vo.setValue(var10001 + " ," + curdate.toString() + " "); + String befdateStr = befdate.toString(); + vo.setValue(befdateStr + " ," + curdate.toString() + " "); } else if (vo.getDataType() == 3 && vo.getOperaCode().equalsIgnoreCase("=")) { UFDate date = new UFDate(vo.getValue()); vo.setValue(date.toLocalString()); vo.setFieldCode(tablealias + "." + vo.getFieldCode()); + } else if (vo.getFieldCode().equalsIgnoreCase("memo")) { + tranMap.put("memo", vo); } else { vo.setFieldCode(tablealias + "." + vo.getFieldCode()); } + if (!vo.getFieldCode().equalsIgnoreCase("memo")) { + list.add(vo); + } } StringBuilder sql = new StringBuilder(""); - sql.append((new ConditionVO()).getSQLStr(copyconvos)); + ConditionVO[] array = list.toArray(new ConditionVO[0]); + sql.append((new ConditionVO()).getSQLStr(array)); this.addMarWhere(sql, tranMap, rptutils, tablealias); return sql.toString(); } diff --git a/purp/src/public/nc/vo/pp/report/util/PurpRptUtils.java b/purp/src/public/nc/vo/pp/report/util/PurpRptUtils.java index fcfae47b..a0bdcaf0 100644 --- a/purp/src/public/nc/vo/pp/report/util/PurpRptUtils.java +++ b/purp/src/public/nc/vo/pp/report/util/PurpRptUtils.java @@ -5,8 +5,6 @@ package nc.vo.pp.report.util; -import java.util.HashMap; -import java.util.Map; import nc.bs.ic.icreport.pub.RPMetaDataUtil; import nc.bs.pubapp.report.ReportPermissionUtils; import nc.pub.smart.context.SmartContext; @@ -22,6 +20,9 @@ import nc.vo.pubapp.pattern.model.meta.entity.view.IDataViewMeta; import nc.vo.scmbd.pub.SCMESAPI; import nc.vo.scmpub.util.ArrayUtil; +import java.util.HashMap; +import java.util.Map; + /** * 最新价格查询 * 2005适配2312 @@ -58,9 +59,9 @@ public class PurpRptUtils { if (vos != null && vos.length > 0) { Object[][] datas = new Object[vos.length][fields.length]; - for(int i = 0; i < vos.length; ++i) { + for (int i = 0; i < vos.length; ++i) { if (vos[i] != null) { - for(int k = 0; k < fields.length; ++k) { + for (int k = 0; k < fields.length; ++k) { datas[i][k] = vos[i].getAttributeValue(fields[k]); } } @@ -96,7 +97,8 @@ public class PurpRptUtils { ConditionVO codeVO = this.getMarCondVO(tranMap, marcodeKey); ConditionVO nameVO = this.getMarCondVO(tranMap, marnameKey); ConditionVO classVO = this.getMarCondVO(tranMap, marclassKey); - if (null == codeVO && null == nameVO && null == classVO) { + boolean flag = tranMap.get("memo") == null; + if (null == codeVO && null == nameVO && null == classVO && flag) { return ""; } else { StringBuilder wheresql = new StringBuilder(); @@ -116,6 +118,11 @@ public class PurpRptUtils { wheresql.append(" and "); this.setMarWhere(classVO, "bd_material.pk_marbasclass", wheresql); } + if (!flag) { + ConditionVO memoVo = (ConditionVO) tranMap.get("memo"); + wheresql.append(" and "); + this.setMarWhere(memoVo, "bd_material.memo", wheresql); + } wheresql.append(" ) "); return wheresql.toString(); @@ -169,6 +176,9 @@ public class PurpRptUtils { } else if (condvo.getOperaCode().equals("left like")) { String value = condvo.getValue().replaceAll("\\(", "").replaceAll("\\)", ""); wheresql.append(field + " like '" + SCMESAPI.sqlEncodeGeneral(value) + "%' "); + } else if (condvo.getOperaCode().equals("like")) { + String value = condvo.getValue().replaceAll("\\(", "").replaceAll("\\)", ""); + wheresql.append(field + " like '%" + SCMESAPI.sqlEncodeGeneral(value) + "%' "); } } From ce99f9aeb1bbcdcda4719e518b8db0dc4ff079b4 Mon Sep 17 00:00:00 2001 From: "zhangxinah@yonyou.com" Date: Thu, 17 Apr 2025 18:39:31 +0800 Subject: [PATCH 10/11] =?UTF-8?q?2312=E6=94=B6=E6=AC=BE=E5=8D=95=E5=A4=96?= =?UTF-8?q?=E5=B8=81=E6=9C=AC=E5=B8=81=E8=AE=A1=E7=AE=97=E8=B0=83=E6=95=B4?= =?UTF-8?q?-=E5=BC=A0=E9=91=AB0417?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resource/GatheringbillRestResource.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/arap/src/public/nc/api/arap/resource/GatheringbillRestResource.java b/arap/src/public/nc/api/arap/resource/GatheringbillRestResource.java index 73dd35c7..28fd1ffc 100644 --- a/arap/src/public/nc/api/arap/resource/GatheringbillRestResource.java +++ b/arap/src/public/nc/api/arap/resource/GatheringbillRestResource.java @@ -138,7 +138,7 @@ public class GatheringbillRestResource extends ArapBaseRestResource { Object tr = dao.executeQuery( "select ntaxrate from so_saleorder_b where csaleorderid = '" + csaleorderid + "'", new ColumnProcessor()); - ntaxrate = new UFDouble(tr.toString()); + //ntaxrate = new UFDouble(tr.toString()); // 税码 Object ctaxcodeid = hybo.findColValue("so_saleorder_b", "ctaxcodeid", "csaleorderid = '" + csaleorderid + "' "); @@ -240,8 +240,12 @@ public class GatheringbillRestResource extends ArapBaseRestResource { itemvo.setNotax_cr(notax_cr); // zhangxinah增加组织本币无税金额(贷方) itemvo.setLocal_notax_cr(notax_cr); - // - itemvo.setRate(UFDouble.ZERO_DBL); + // 汇率为空时,默认为1 + if (headvo.getRate() == null) { + itemvo.setRate(UFDouble.ONE_DBL); + } else { + itemvo.setRate(headvo.getRate()); + } // itemvo.setTaxcodeid(ctaxcode); // @@ -249,7 +253,8 @@ public class GatheringbillRestResource extends ArapBaseRestResource { // 收支项目 itemvo.setPk_subjcode("201"); money = money.add(itemvo.getMoney_cr()); - itemvo.setLocal_money_cr(itemvo.getMoney_cr()); + itemvo.setLocal_money_cr( + itemvo.getMoney_cr().multiply(itemvo.getRate()).setScale(2, UFDouble.ROUND_HALF_UP)); Object def2 = itemvo.getDef2(); if (def2 != null) itemvo.setDef2(hybo.findColValue("bd_defdoc", "pk_defdoc", " code = '" + def2 + "' ") + ""); @@ -288,8 +293,8 @@ public class GatheringbillRestResource extends ArapBaseRestResource { headvo.setMoney(money); headvo.setGloballocal(money); - headvo.setRate(new UFDouble(1)); - headvo.setLocal_money(money); + // headvo.setRate(new UFDouble(1)); + headvo.setLocal_money(money.multiply(headvo.getRate()).setScale(2, UFDouble.ROUND_HALF_UP)); AggGatheringBillVO bill = new AggGatheringBillVO(); bill.setParentVO(headvo); bill.setChildrenVO((CircularlyAccessibleValueObject[]) itemvos.toArray(new GatheringBillItemVO[0])); From fa7b31cf70990ea1c158c0a8126a9a10d5c6223a Mon Sep 17 00:00:00 2001 From: mzr Date: Thu, 17 Apr 2025 20:12:13 +0800 Subject: [PATCH 11/11] =?UTF-8?q?=E9=94=80=E5=94=AE=E5=8F=91=E7=A5=A8?= =?UTF-8?q?=E7=BA=A2=E5=86=B2=E6=8E=A5=E5=8F=A3-=E6=95=B0=E9=87=8F?= =?UTF-8?q?=E9=87=91=E9=A2=9D=E5=8F=96=E5=80=BC=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../operator/IAPISaleInvMaitainImpl.java | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/so/src/public/nccloud/api/so/saleinvoice/operator/IAPISaleInvMaitainImpl.java b/so/src/public/nccloud/api/so/saleinvoice/operator/IAPISaleInvMaitainImpl.java index 9844d78f..855ee718 100644 --- a/so/src/public/nccloud/api/so/saleinvoice/operator/IAPISaleInvMaitainImpl.java +++ b/so/src/public/nccloud/api/so/saleinvoice/operator/IAPISaleInvMaitainImpl.java @@ -44,6 +44,12 @@ import java.math.RoundingMode; import java.util.List; import java.util.Map; +/** + * 销售发票红冲接口服务实现类 + * + * @author mzr + * @date 20250417 + */ public class IAPISaleInvMaitainImpl { public static String fplxStr = "";// 开票申请发票类型 @@ -483,12 +489,28 @@ public class IAPISaleInvMaitainImpl { UFDouble nastnum = new UFDouble(bipBvoJson.getString("nastnum")); newInvBVO.setNastnum(nastnum.multiply(vchangerateNum).setScale(2, 4)); // 数量 newInvBVO.setNnum(nastnum); // 主数量 + newInvBVO.setNqtorigtaxprice(new UFDouble(bipBvoJson.getString("nqtorigtaxprice"))); // 含税单价 + newInvBVO.setNqtorigprice(new UFDouble(bipBvoJson.getString("nqtorigprice"))); // 无税单价 + newInvBVO.setNorigtaxprice(new UFDouble(bipBvoJson.getString("norigtaxprice"))); // 主含税单价 + newInvBVO.setNorigprice(new UFDouble(bipBvoJson.getString("norigprice"))); // 主无税单价 + newInvBVO.setNorigtaxnetprice(new UFDouble(bipBvoJson.getString("norigtaxnetprice"))); // 主含税净价 + newInvBVO.setNorignetprice(new UFDouble(bipBvoJson.getString("norignetprice"))); // 主无税净价 + newInvBVO.setNqtorigtaxnetprc(new UFDouble(bipBvoJson.getString("nqtorigtaxnetprc"))); // 含税净价 + newInvBVO.setNqtorignetprice(new UFDouble(bipBvoJson.getString("nqtorignetprice"))); // 无税净价 + newInvBVO.setNtaxprice(new UFDouble(bipBvoJson.getString("ntaxprice"))); // 主本币含税单价 + newInvBVO.setNprice(new UFDouble(bipBvoJson.getString("nprice"))); // 主本币无税单价 + newInvBVO.setNtaxnetprice(new UFDouble(bipBvoJson.getString("ntaxnetprice"))); // 主本币含税净价 + newInvBVO.setNnetprice(new UFDouble(bipBvoJson.getString("nnetprice"))); // 主本币无税净价 + newInvBVO.setNqttaxprice(new UFDouble(bipBvoJson.getString("nqttaxprice"))); // 本币含税单价 + newInvBVO.setNqtprice(new UFDouble(bipBvoJson.getString("nqtprice"))); // 本币无税单价 + newInvBVO.setNqttaxnetprice(new UFDouble(bipBvoJson.getString("nqttaxnetprice"))); // 本币含税净价 + newInvBVO.setNqtnetprice(new UFDouble(bipBvoJson.getString("nqtnetprice"))); // 本币无税净价 newInvBVO.setNtax(new UFDouble(bipBvoJson.getString("ntax"))); // 税额 - newInvBVO.setNmny(new UFDouble(bipBvoJson.getString("nmny"))); // 本币无税金额 - newInvBVO.setNtaxmny(new UFDouble(bipBvoJson.getString("ntaxmny"))); // 本币价税合计 - newInvBVO.setNcaltaxmny(new UFDouble(bipBvoJson.getString("ncaltaxmny"))); // 计税金额 newInvBVO.setNorigmny(new UFDouble(bipBvoJson.getString("norigmny"))); // 无税金额 newInvBVO.setNorigtaxmny(new UFDouble(bipBvoJson.getString("norigtaxmny"))); // 价税合计 + newInvBVO.setNmny(new UFDouble(bipBvoJson.getString("nmny"))); // 本币无税金额 + newInvBVO.setNtaxmny(new UFDouble(bipBvoJson.getString("ntaxmny"))); // 本币价税合计 + newInvBVO.setNcaltaxmny(new UFDouble(bipBvoJson.getString("nmny"))); // 计税金额=本币无税金额 newInvBVO.setCopposesrcbid(bipBvoJson.getString("vbdef15")); // 对冲来源子表id newInvBVO.setNqtunitnum(null); // 报价数量 newInvBVO.setCsaleinvoiceid(null); // 发票关联主表id