From 777419f1a9fdc2575bf366fc758f425ded38cc27 Mon Sep 17 00:00:00 2001 From: mzr Date: Sun, 27 Apr 2025 12:32:56 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BA=A2=E5=86=B2=E5=8F=91=E7=A5=A8=E7=94=9F?= =?UTF-8?q?=E6=88=90=E5=BC=80=E7=A5=A8=E7=94=B3=E8=AF=B7=E8=B0=83=E8=AF=95?= =?UTF-8?q?=E6=8A=A5=E9=94=99=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ApplicationRedInvoiceService.java | 16 +- .../operator/IAPISaleInvMaitainImpl.java | 186 ++++++++++-------- 2 files changed, 113 insertions(+), 89 deletions(-) diff --git a/so/src/public/nccloud/api/so/saleinvoice/operator/ApplicationRedInvoiceService.java b/so/src/public/nccloud/api/so/saleinvoice/operator/ApplicationRedInvoiceService.java index 5f214fc..03e2cbf 100644 --- a/so/src/public/nccloud/api/so/saleinvoice/operator/ApplicationRedInvoiceService.java +++ b/so/src/public/nccloud/api/so/saleinvoice/operator/ApplicationRedInvoiceService.java @@ -1,5 +1,6 @@ package nccloud.api.so.saleinvoice.operator; +import nc.bs.framework.common.NCLocator; import nc.vo.pub.BusinessException; import nc.vo.pub.lang.UFDouble; import nc.vo.pubapp.pattern.log.Log; @@ -13,10 +14,8 @@ import nc.vo.so.m32trantype.enumeration.Finvoicetime; import nc.vo.so.pub.enumeration.BillStatus; import nc.vo.so.pub.util.AggVOUtil; import nccloud.framework.core.exception.ExceptionUtils; -import nccloud.framework.service.ServiceLocator; import nccloud.itf.sscivm.ivsale.service.ExchangeToIvAppService; import nccloud.pubitf.so.saleinvoice.service.IM32TransTypeService; -import nccloud.web.scmpub.pub.action.group.SysInitGroupQueryNcc; import java.util.ArrayList; import java.util.HashMap; @@ -40,10 +39,6 @@ public class ApplicationRedInvoiceService { public List> getData(SaleInvoiceVO[] vos) { Map>> dealMnyMap = new HashMap>>(); try { - if (!SysInitGroupQueryNcc.isEndable("1058")) { - ExceptionUtils.wrapBusinessException( - nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("4006013_0", "04006013-0038")/* @res "请启用发票管理模块!" */); - } Map isCanGenerateMap = this.checkInvoiceStatus(AggVOUtil.getPrimaryKeys(vos)); Map invoicetime = this.qryinvoicetime(vos); @@ -91,10 +86,11 @@ public class ApplicationRedInvoiceService { if (ValueCheckUtil.isNullORZeroLength(billIds)) { return new HashMap(); } - if (!SysInitGroupQueryNcc.isEndable("1058")) { + /*if (!SysInitGroupQueryNcc.isEndable("1058")) { return new HashMap(); - } - return ServiceLocator.find(ExchangeToIvAppService.class).checkApplicationStatus(billIds); + }*/ + ExchangeToIvAppService exchangeToIvAppService = NCLocator.getInstance().lookup(ExchangeToIvAppService.class); + return exchangeToIvAppService.checkApplicationStatus(billIds); } /** @@ -113,7 +109,7 @@ public class ApplicationRedInvoiceService { // 默认先审批通过后开票 if (null != trantypeids && !trantypeids.isEmpty()) { try { - IM32TransTypeService service = ServiceLocator.find(IM32TransTypeService.class); + IM32TransTypeService service = NCLocator.getInstance().lookup(IM32TransTypeService.class); tranttypeMap = service.queryM32TranType(trantypeids.toArray(new String[0])); } catch (Exception e) { Log.info(e); 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 b8ca3c2..470178d 100644 --- a/so/src/public/nccloud/api/so/saleinvoice/operator/IAPISaleInvMaitainImpl.java +++ b/so/src/public/nccloud/api/so/saleinvoice/operator/IAPISaleInvMaitainImpl.java @@ -30,7 +30,6 @@ import nccloud.api.rest.utils.ResultMessageUtil; import nccloud.commons.lang.StringUtils; import nccloud.dto.scmpub.script.entity.SCMScriptResultDTO; import nccloud.framework.core.exception.ExceptionUtils; -import nccloud.framework.service.ServiceLocator; import nccloud.itf.sscivm.ivsale.service.IVApplicationInvoiceService; import nccloud.pubitf.riart.pflow.CloudPFlowContext; import nccloud.pubitf.riart.pflow.ICloudScriptPFlowService; @@ -205,7 +204,7 @@ public class IAPISaleInvMaitainImpl { // 查询新生成红冲发票的信息 String newPk = returnApproveSaleInvoiceVOs[0].getParentVO().getCsaleinvoiceid(); String[] idsNew = {newPk}; - // String[] idsNew = {"1001A11000000FREYYLE"}; + // String[] idsNew = {"1001A11000000FSB45YA"}; SaleInvoiceVO[] redVos = querySaleInvoiceByIds(idsNew); /** @@ -567,8 +566,113 @@ public class IAPISaleInvMaitainImpl { } } + public IVApplicationAggVO saveIVApplication(JSONObject bject, SaleInvoiceVO[] redVos) throws Exception { + SaleInvoiceHVO redHvo = redVos[0].getParentVO(); + // 获取 红字发票传开票申请的数据 + ApplicationRedInvoiceService applicationRedInvoiceService = new ApplicationRedInvoiceService(); + List> jeMap = applicationRedInvoiceService.getData(redVos); + + IVApplicationAggVO applyVo = null; + + String invId = bject.getOrDefault("vdef40", "") + ""; + + // 查询蓝字发票号对应的税务云开出的发票号 + String invCode = getSaleInvCode(invId); + if (StringUtils.isBlank(invCode) || "null".equals(invCode)) { + ExceptionUtils.wrapBusinessException("税务云的发票号不能为空"); + } + IVApplicationInvoiceService ivService = NCLocator.getInstance().lookup(IVApplicationInvoiceService.class); + JSONObject jsonObject1 = new JSONObject(); + // 构造开票申请的VO + IVApplicationAggVO[] applicationAggVOS = ivService.getRedInvoice("", invCode, jsonObject1); + Logger.error("saveIVApplication-jsonObject1 = " + jsonObject1); + if (applicationAggVOS != null) { + String src_billid = redHvo.getCsaleinvoiceid(); + String src_pk_org = redHvo.getPk_org(); + String src_billno = redHvo.getVbillcode(); + // String src_billtypeid = ""; + String src_tradetypeid = redHvo.getCtrantypeid(); + applicationAggVOS[0].getParentVO().setSrc_jx_billid(src_billid); + applicationAggVOS[0].getParentVO().setSrc_jx_billno(src_billno); + applicationAggVOS[0].getParentVO().setSrc_jx_billtypeid("32"); + applicationAggVOS[0].getParentVO().setSrc_jx_sporg(src_pk_org); + // applicationAggVOS[0].getParentVO().setSrc_jx_spr(src_spr); + applicationAggVOS[0].getParentVO().setSrc_jx_tradetypeid(src_tradetypeid); + } + JSONObject jsonObject = new JSONObject(); + // ntotalorigmny 价税合计 + UFDouble ntotalorigmny = redHvo.getNtotalorigmny() == null ? UFDouble.ZERO_DBL : redHvo.getNtotalorigmny(); + for (IVApplicationAggVO applicationAggVO : applicationAggVOS) { + // 在开具红字发票时,如果红冲的发票为增值税专用发票,红字信息申请表不能为空 + IVApplicationHeadVO headVO = applicationAggVO.getParentVO(); + // 红字信息申请表-赋值 + // headVO.setHzxxsqb("红字信息申请表"); + + IVApplicationBodyVO[] bodyVOs = applicationAggVO.getBodyVOs(); + UFDouble ntotalorigmnyDiv = ntotalorigmny.div(new UFDouble(bodyVOs.length)).setScale(2, UFDouble.ROUND_HALF_UP); + for (IVApplicationBodyVO bodyVO : bodyVOs) { + // bchcje 本次红冲金额的赋值(负数转正数) + bodyVO.setBchcje(new UFDouble(ntotalorigmnyDiv).multiply(new UFDouble(-1))); + } + } + // 红字发票生成开票申请动作 + IVApplicationAggVO[] ivApplicationVOs = ivService.makeRedInvoice(applicationAggVOS, jsonObject, jeMap); + if (ivApplicationVOs != null && ivApplicationVOs.length > 0) { + applyVo = ivApplicationVOs[0]; + } + Logger.error("saveIVApplication-msg = " + jsonObject); + return applyVo; + } + + + private 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()); + } + /** - * 构造红冲开票申请VO + * 根据税务云单号查询发票的单号 + * + * @param invId + * @return + * @throws BusinessException + */ + private String getSaleInvCode(String invId) throws BusinessException { + IUAPQueryBS queryBS = NCLocator.getInstance().lookup(IUAPQueryBS.class); + String sql = " select nvl(vdef13, '') vdef13" + + " from so_saleinvoice" + + " where nvl(dr,0) = 0 and csaleinvoiceid = '" + invId + "' "; + Map resMap = (Map) queryBS.executeQuery(sql, new MapProcessor()); + return resMap.getOrDefault("vdef13", ""); + } + + private String getString_TrimAsNull(Object value) { + if ((value == null) || (value.toString().trim().isEmpty())) { + return ""; + } + return value.toString().trim(); + } + + private 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 applyHeadVO 原开票申请主实体 * @param ivApplicationBodyVOS 原开票申请子实体 @@ -663,80 +767,4 @@ public class IAPISaleInvMaitainImpl { } } - public IVApplicationAggVO saveIVApplication(JSONObject bject, SaleInvoiceVO[] redVos) throws Exception { - // 获取 红字发票传开票申请的数据 - ApplicationRedInvoiceService applicationRedInvoiceService = new ApplicationRedInvoiceService(); - List> jeMap = applicationRedInvoiceService.getData(redVos); - - IVApplicationAggVO applyVo = null; - - String invId = bject.getOrDefault("vdef40", "") + ""; - - // 查询蓝字发票号对应的税务云开出的发票号 - String invCode = getSaleInvCode(invId); - if (StringUtils.isBlank(invCode) || "null".equals(invCode)) { - ExceptionUtils.wrapBusinessException("税务云的发票号不能为空"); - } - IVApplicationInvoiceService ivService = ServiceLocator.find(IVApplicationInvoiceService.class); - JSONObject jsonObject1 = new JSONObject(); - // 查询对应的蓝字发票 - IVApplicationAggVO[] blueVos = ivService.getRedInvoice("", invCode, jsonObject1); - Logger.error("saveIVApplication-jsonObject1 = " + jsonObject1); - JSONObject jsonObject = new JSONObject(); - // 红字发票生成开票申请动作 - IVApplicationAggVO[] ivApplicationVOs = ivService.makeRedInvoice(blueVos, jsonObject, jeMap); - if (ivApplicationVOs != null && ivApplicationVOs.length > 0) { - applyVo = ivApplicationVOs[0]; - } - Logger.error("saveIVApplication-msg = " + jsonObject); - return applyVo; - } - - - private 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()); - } - - /** - * 根据税务云单号查询发票的单号 - * - * @param invId - * @return - * @throws BusinessException - */ - private String getSaleInvCode(String invId) throws BusinessException { - IUAPQueryBS queryBS = NCLocator.getInstance().lookup(IUAPQueryBS.class); - String sql = " select nvl(vdef13, '') vdef13" + - " from so_saleinvoice" + - " where nvl(dr,0) = 0 and csaleinvoiceid = '" + invId + "' "; - Map resMap = (Map) queryBS.executeQuery(sql, new MapProcessor()); - return resMap.getOrDefault("vbillcode", ""); - } - - private String getString_TrimAsNull(Object value) { - if ((value == null) || (value.toString().trim().isEmpty())) { - return ""; - } - return value.toString().trim(); - } - - private 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()); - } - }