diff --git a/sscivm/src/public/nc/bs/sscivm/ivsale/util/InvoiceTransferUtil.java b/sscivm/src/public/nc/bs/sscivm/ivsale/util/InvoiceTransferUtil.java index 10b0c37..7cf39e3 100644 --- a/sscivm/src/public/nc/bs/sscivm/ivsale/util/InvoiceTransferUtil.java +++ b/sscivm/src/public/nc/bs/sscivm/ivsale/util/InvoiceTransferUtil.java @@ -12,11 +12,7 @@ import nc.bs.sscivm.ivsale.splitmerge.util.TransSpiltMergePksUtil; import nc.bs.sscivm.logger.SSCIVMLogger; import nc.dto.imag.boot.RequestInfo; import nc.dto.imag.boot.ResponseInfo; -import nc.dto.imag.invoice.PInvoice; -import nc.dto.imag.invoice.PInvoiceCepz; -import nc.dto.imag.invoice.PInvoiceDetail; -import nc.dto.imag.invoice.PInvoiceSDetail; -import nc.dto.imag.invoice.PInvoiceTspz; +import nc.dto.imag.invoice.*; import nc.dto.imag.invoice.tax.InvalidCommonRequest; import nc.dto.imag.invoice.tax.InvalidCommonResponse; import nc.dto.imag.invoice.tax.TaxCommonResponse; @@ -39,27 +35,9 @@ import nc.vo.pub.lang.UFBoolean; import nc.vo.pub.lang.UFDate; import nc.vo.pub.lang.UFDateTime; import nc.vo.pub.lang.UFDouble; -import nc.vo.sscivm.invoice.IVMInvoiceAggVO; -import nc.vo.sscivm.invoice.IVMInvoiceConstant; -import nc.vo.sscivm.invoice.IVMInvoiceDetailVO; -import nc.vo.sscivm.invoice.IVMInvoiceHeadVO; -import nc.vo.sscivm.invoice.IVMInvoiceRelationVO; -import nc.vo.sscivm.invoice.IVMInvoiceTspzDetailVO; -import nc.vo.sscivm.ivmpub.ClassTypeEnum; -import nc.vo.sscivm.ivmpub.IVAplocationFPXZ; -import nc.vo.sscivm.ivmpub.IVAplocationKPFS; -import nc.vo.sscivm.ivmpub.IVAplocationLSLBS; -import nc.vo.sscivm.ivmpub.IVAplocationZSFS; -import nc.vo.sscivm.ivmpub.InvoiceStatus; -import nc.vo.sscivm.ivmpub.InvoiceTypeEnum; -import nc.vo.sscivm.ivmpub.IsHzfp; -import nc.vo.sscivm.ivmpub.KpztEnum; -import nc.vo.sscivm.ivsale.IVApplicationAggVO; -import nc.vo.sscivm.ivsale.IVApplicationBodyVO; -import nc.vo.sscivm.ivsale.IVApplicationHeadVO; -import nc.vo.sscivm.ivsale.IVApplicationRelationVO; -import nc.vo.sscivm.ivsale.IVApplogVO; -import nc.vo.sscivm.ivsale.IVTspzsBodyVO; +import nc.vo.sscivm.invoice.*; +import nc.vo.sscivm.ivmpub.*; +import nc.vo.sscivm.ivsale.*; import nc.vo.trade.pub.IBillStatus; import nccloud.commons.lang.StringUtils; import nccloud.itf.sscivm.ivsale.service.ApplicationLogService; @@ -68,17 +46,7 @@ import nccloud.putitf.riart.billtype.IBilltypeService; import java.math.BigDecimal; import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; -import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; public class InvoiceTransferUtil { @@ -107,8 +75,8 @@ public class InvoiceTransferUtil { List invoices = new ArrayList(); for (IVApplicationAggVO vo : vos) { - applyRequest.addEmail(vo.getParentVO().getPk_ivapplication(), null, null, new String[] {vo.getParentVO().getEmail()}); - applyRequest.addSMS(vo.getParentVO().getPk_ivapplication(), null, null, new String[] {vo.getParentVO().getSms()}); + applyRequest.addEmail(vo.getParentVO().getPk_ivapplication(), null, null, new String[]{vo.getParentVO().getEmail()}); + applyRequest.addSMS(vo.getParentVO().getPk_ivapplication(), null, null, new String[]{vo.getParentVO().getSms()}); requet.setPk_org(vo.getParentVO().getPk_org()); PInvoice invoice = getPInvoiceByApplyHead(vo.getParentVO()); @@ -116,7 +84,7 @@ public class InvoiceTransferUtil { List details = new ArrayList(); for (IVApplicationBodyVO detailvo : vo.getBodyVOs()) { - if(detailvo.getCaninvoice_xmjshj().compareTo(UFDouble.ZERO_DBL)==0){ + if (detailvo.getCaninvoice_xmjshj().compareTo(UFDouble.ZERO_DBL) == 0) { continue; } PInvoiceDetail detail = getPInvoiceByApplyHead(vo.getParentVO(), detailvo); @@ -127,9 +95,9 @@ public class InvoiceTransferUtil { invoice.setItems(details.toArray(new PInvoiceDetail[0])); - //数电票特殊票种 + // 数电票特殊票种 IVTspzsBodyVO[] tspzVOs = vo.getIvTspzsBodyVO(); - if (tspzVOs != null && tspzVOs.length > 0){ + if (tspzVOs != null && tspzVOs.length > 0) { invoice = getPInvoiceByApplyTspz(tspzVOs, invoice); } invoices.add(invoice); @@ -165,8 +133,8 @@ public class InvoiceTransferUtil { + " = '" + logvo.getFphm() + "' ) " + " and (" + IVApplogVO.KPZT + " =" + KpztEnum.ZFING + " or " + IVApplogVO.KPZT + " =" + KpztEnum.ZFERR + " )" + " and " + IVApplogVO.ISSYNC + " ='Y' "; - if (logvo.getFpdm() == null){ - condition = " ( " + IVMInvoiceHeadVO.FPHM + if (logvo.getFpdm() == null) { + condition = " ( " + IVMInvoiceHeadVO.FPHM + " = '" + logvo.getFphm() + "' ) " + " and (" + IVApplogVO.KPZT + " =" + KpztEnum.ZFING + " or " + IVApplogVO.KPZT + " =" + KpztEnum.ZFERR + " )" + " and " + IVApplogVO.ISSYNC + " ='Y' "; @@ -212,7 +180,7 @@ public class InvoiceTransferUtil { String condition = " ( " + IVMInvoiceHeadVO.FPDM + " = '" + logvo.getFpdm() + "' and " + IVMInvoiceHeadVO.FPHM + " = '" + logvo.getFphm() + "' ) " + " and " + IVApplogVO.KPZT + " =" + KpztEnum.ZFING + " " + " and " + IVApplogVO.ISSYNC + " ='Y' "; - if ( logvo.getFpdm() == null){ + if (logvo.getFpdm() == null) { condition = " ( " + IVMInvoiceHeadVO.FPHM + " = '" + logvo.getFphm() + "' ) " + " and " + IVApplogVO.KPZT + " =" + KpztEnum.ZFING + " " + " and " + IVApplogVO.ISSYNC + " ='Y' "; @@ -260,14 +228,14 @@ public class InvoiceTransferUtil { List invoices = new ArrayList(); for (IVApplicationAggVO vo : vos) { requet.setPk_org(vo.getParentVO().getPk_org()); - redRequest.addEmail(vo.getParentVO().getPk_ivapplication(), new String[] {vo.getParentVO().getEmail()}); - redRequest.addSMS(vo.getParentVO().getPk_ivapplication(), new String[] {vo.getParentVO().getSms()}); + redRequest.addEmail(vo.getParentVO().getPk_ivapplication(), new String[]{vo.getParentVO().getEmail()}); + redRequest.addSMS(vo.getParentVO().getPk_ivapplication(), new String[]{vo.getParentVO().getSms()}); PInvoice invoice = getPInvoiceByApplyHead4Red(vo.getParentVO()); List details = new ArrayList(); for (IVApplicationBodyVO detailvo : vo.getBodyVOs()) { - if(detailvo.getCaninvoice_xmjshj().compareTo(UFDouble.ZERO_DBL)==0){ + if (detailvo.getCaninvoice_xmjshj().compareTo(UFDouble.ZERO_DBL) == 0) { continue; } PInvoiceDetail detail = getPInvoiceByApplybody4Red(detailvo); @@ -307,7 +275,7 @@ public class InvoiceTransferUtil { InvalidCommonRequest cr = new InvalidCommonRequest(); cr.setFpHm(invoice.getFphm()); cr.setFpDm(invoice.getFpdm()); - cr.setZfr(invoice.getKpr());//获取开票人原始逻辑,为空则为当前操作人 + cr.setZfr(invoice.getKpr());// 获取开票人原始逻辑,为空则为当前操作人 requet.setData(cr); return requet; @@ -331,12 +299,12 @@ public class InvoiceTransferUtil { IVApplogVO logvo = new IVApplogVO(); - String condition = " " + IVMInvoiceHeadVO.FPDM + " = '" + apply.getParentVO().getFpdm() + "' and " + String condition = " " + IVMInvoiceHeadVO.FPDM + " = '" + apply.getParentVO().getFpdm() + "' and " + IVMInvoiceHeadVO.FPHM + " = '" + apply.getParentVO().getFphm() + "' and dr=0 and " - + IVMInvoiceHeadVO.BILLTYPECODE + "='" + IVAWebConst.IVA_XXFP_JYLXBM +"' "; - if (apply.getParentVO().getFpdm() == null){ - condition = " " + IVMInvoiceHeadVO.FPHM + " = '" + apply.getParentVO().getFphm() + "' and dr=0 and " - + IVMInvoiceHeadVO.BILLTYPECODE + "='" + IVAWebConst.IVA_XXFP_JYLXBM +"' "; + + IVMInvoiceHeadVO.BILLTYPECODE + "='" + IVAWebConst.IVA_XXFP_JYLXBM + "' "; + if (apply.getParentVO().getFpdm() == null) { + condition = " " + IVMInvoiceHeadVO.FPHM + " = '" + apply.getParentVO().getFphm() + "' and dr=0 and " + + IVMInvoiceHeadVO.BILLTYPECODE + "='" + IVAWebConst.IVA_XXFP_JYLXBM + "' "; } IVMInvoiceAggVO[] ivMInvoiceAggVOS = NCLocator @@ -471,20 +439,20 @@ public class InvoiceTransferUtil { * @return * @throws BusinessException */ - public static List getResult4BlueInvoiceApply(IVApplicationAggVO[] ivApplicationVOs,ResponseInfo response) + public static List getResult4BlueInvoiceApply(IVApplicationAggVO[] ivApplicationVOs, ResponseInfo response) throws BusinessException { if (!IVMInvoiceConstant.SUCCESS_CODE.equals(response.getCode())) { throw new BusinessException(response.getMessage()); } - //是否NCC拆分合并 - boolean splitMerge =true; - if(ivApplicationVOs[0]!=null && ivApplicationVOs[0].getBodyVOs()[0].getPk_ivappdetail().length() == 20){ + // 是否NCC拆分合并 + boolean splitMerge = true; + if (ivApplicationVOs[0] != null && ivApplicationVOs[0].getBodyVOs()[0].getPk_ivappdetail().length() == 20) { splitMerge = false; } List logs = new ArrayList(); - //1、 平台处理后只有返回成功的数据,如果税务云返回失败会直接抛出异常 + // 1、 平台处理后只有返回成功的数据,如果税务云返回失败会直接抛出异常 PInvoice[] invoices = response.getData().getInvoices(); if (invoices != null) { @@ -494,95 +462,94 @@ public class InvoiceTransferUtil { } } - //2、记录发票与开票申请行关联关系,并再次更新 - if(ivApplicationVOs.length > 0 ){ - Set addApplicationRelationVO =new HashSet();//汇总需要更新的内容 - Set deleteApplicationRelationVO =new HashSet();//汇总需要删除的内容 - //判断返回的每条开票申请对应的数据,如果出现下游税务云返回票据多于上游记录关系,或者上游无关系。(说明下游税务云存在自动拆分,或纯手工开票场景。也使用NCC的拆分合并关联关系表管理) + // 2、记录发票与开票申请行关联关系,并再次更新 + if (ivApplicationVOs.length > 0) { + Set addApplicationRelationVO = new HashSet();// 汇总需要更新的内容 + Set deleteApplicationRelationVO = new HashSet();// 汇总需要删除的内容 + // 判断返回的每条开票申请对应的数据,如果出现下游税务云返回票据多于上游记录关系,或者上游无关系。(说明下游税务云存在自动拆分,或纯手工开票场景。也使用NCC的拆分合并关联关系表管理) for (IVApplicationAggVO aggVOOld : ivApplicationVOs) { - IVApplicationAggVO aggVO = aggVOOld.clone();//避免污染原始VO + IVApplicationAggVO aggVO = aggVOOld.clone();// 避免污染原始VO String pk_ivapplication = aggVO.getParentVO().getPk_ivapplication(); boolean zffp = aggVO.getParentVO().getZffp() == null ? false : aggVO.getParentVO().getZffp().booleanValue();// 是否作废开票申请单 boolean hzfp = aggVO.getParentVO().getHzfp() == null ? false : aggVO.getParentVO().getHzfp().booleanValue();// 是否红字开票申请单 - IVApplicationBodyVO[] iVApplicationBodyVOS= aggVO.getBodyVOs(); - Set childIVApplogVOS =new HashSet(); - //2.1当前开票申请与开票情况的关系合集 - if(logs.size()>0){ - for (IVApplogVO log:logs) { - if(Arrays.asList(TransSpiltMergePksUtil.transIvapplicationToLyid(new String[]{pk_ivapplication})).contains(log.getLyid())){ + IVApplicationBodyVO[] iVApplicationBodyVOS = aggVO.getBodyVOs(); + Set childIVApplogVOS = new HashSet(); + // 2.1当前开票申请与开票情况的关系合集 + if (logs.size() > 0) { + for (IVApplogVO log : logs) { + if (Arrays.asList(TransSpiltMergePksUtil.transIvapplicationToLyid(new String[]{pk_ivapplication})).contains(log.getLyid())) { childIVApplogVOS.add(log); } } } - //2.2蓝票或者重开场景重新设置值 + // 2.2蓝票或者重开场景重新设置值 // 非作废申请,红冲申请 - if(!zffp&&!hzfp&&childIVApplogVOS.size()>0){ - //匹配到生成的开票情况有内容 - for (IVApplogVO childIVApplogVO:childIVApplogVOS) { + if (!zffp && !hzfp && childIVApplogVOS.size() > 0) { + // 匹配到生成的开票情况有内容 + for (IVApplogVO childIVApplogVO : childIVApplogVOS) { PInvoiceDetail[] invoicedetails = childIVApplogVO.getItems(); - if(invoicedetails.length>0){ - for(PInvoiceDetail invoicedetail:invoicedetails){ - for(IVApplicationBodyVO iVApplicationBodyVO:iVApplicationBodyVOS){ - if(iVApplicationBodyVO.getHh().equals(invoicedetail.getHh())){ - UFDouble invoice_xmsl = new UFDouble(invoicedetail.getXmsl()==null?new BigDecimal(0):invoicedetail.getXmsl()); - UFDouble invoice_xmje = new UFDouble(invoicedetail.getXmje()==null?new BigDecimal(0):invoicedetail.getXmje()); - UFDouble invoice_xmjshj = new UFDouble(invoicedetail.getXmjshj()==null?new BigDecimal(0):invoicedetail.getXmjshj()); + if (invoicedetails.length > 0) { + for (PInvoiceDetail invoicedetail : invoicedetails) { + for (IVApplicationBodyVO iVApplicationBodyVO : iVApplicationBodyVOS) { + if (iVApplicationBodyVO.getHh().equals(invoicedetail.getHh())) { + UFDouble invoice_xmsl = new UFDouble(invoicedetail.getXmsl() == null ? new BigDecimal(0) : invoicedetail.getXmsl()); + UFDouble invoice_xmje = new UFDouble(invoicedetail.getXmje() == null ? new BigDecimal(0) : invoicedetail.getXmje()); + UFDouble invoice_xmjshj = new UFDouble(invoicedetail.getXmjshj() == null ? new BigDecimal(0) : invoicedetail.getXmjshj()); boolean zkh = invoice_xmjshj.compareTo(UFDouble.ZERO_DBL) < 0; - if(splitMerge){//判断NCC拆分合并场景 - JSONArray arr = JSONArray.parseArray(iVApplicationBodyVO.getPk_ivappdetail()); - //对arr进行排序 + if (splitMerge) {// 判断NCC拆分合并场景 + JSONArray arr = JSONArray.parseArray(iVApplicationBodyVO.getPk_ivappdetail()); + // 对arr进行排序 List arrList = JSONArray.parseArray(arr.toJSONString(), JSONObject.class); Collections.sort(arrList, new Comparator() { @Override public int compare(JSONObject o1, JSONObject o2) { - UFDouble jshj1 = new UFDouble(o1.getBigDecimal(IVApplicationBodyVO.XMJSHJ)); - UFDouble jshj2 = new UFDouble(o2.getBigDecimal(IVApplicationBodyVO.XMJSHJ)); + UFDouble jshj1 = new UFDouble(o1.getBigDecimal(IVApplicationBodyVO.XMJSHJ)); + UFDouble jshj2 = new UFDouble(o2.getBigDecimal(IVApplicationBodyVO.XMJSHJ)); return jshj1.compareTo(jshj2); } }); arr = JSONArray.parseArray(arrList.toString()); JSONArray update_arr = new JSONArray(); - //获取剩余的拆合列表,并还原到PK_IVAPPDETAIL中 - for(int i = 0;i < arr.size();i++) { - String pk_ivapplication_split = arr.getJSONObject(i).getString(IVApplicationBodyVO.PK_IVAPPLICATION); - String pk_ivappdetail = arr.getJSONObject(i).getString(IVApplicationBodyVO.PK_IVAPPDETAIL); - UFDouble split_xmsl = new UFDouble(arr.getJSONObject(i).getBigDecimal(IVApplicationBodyVO.XMSL)); - UFDouble split_xmje = new UFDouble(arr.getJSONObject(i).getBigDecimal(IVApplicationBodyVO.XMJE)); - UFDouble split_xmjshj = new UFDouble(arr.getJSONObject(i).getBigDecimal(IVApplicationBodyVO.XMJSHJ)); - //按金额回写 - if(invoice_xmjshj.compareTo(UFDouble.ZERO_DBL)==0){ - //当前发票金额已用完 + // 获取剩余的拆合列表,并还原到PK_IVAPPDETAIL中 + for (int i = 0; i < arr.size(); i++) { + String pk_ivapplication_split = arr.getJSONObject(i).getString(IVApplicationBodyVO.PK_IVAPPLICATION); + String pk_ivappdetail = arr.getJSONObject(i).getString(IVApplicationBodyVO.PK_IVAPPDETAIL); + UFDouble split_xmsl = new UFDouble(arr.getJSONObject(i).getBigDecimal(IVApplicationBodyVO.XMSL)); + UFDouble split_xmje = new UFDouble(arr.getJSONObject(i).getBigDecimal(IVApplicationBodyVO.XMJE)); + UFDouble split_xmjshj = new UFDouble(arr.getJSONObject(i).getBigDecimal(IVApplicationBodyVO.XMJSHJ)); + // 按金额回写 + if (invoice_xmjshj.compareTo(UFDouble.ZERO_DBL) == 0) { + // 当前发票金额已用完 break; - } - else if((split_xmjshj.compareTo(invoice_xmjshj)<=0 && !zkh) || (split_xmjshj.compareTo(invoice_xmjshj)>=0 && zkh)){ - //当前拆分金额已用完 + } else if ((split_xmjshj.compareTo(invoice_xmjshj) <= 0 && !zkh) || (split_xmjshj.compareTo(invoice_xmjshj) >= 0 && zkh)) { + // 当前拆分金额已用完 invoice_xmjshj = invoice_xmjshj.sub(split_xmjshj); invoice_xmje = invoice_xmje.sub(split_xmje); invoice_xmsl = invoice_xmsl.sub(split_xmsl); - if(split_xmjshj.compareTo(UFDouble.ZERO_DBL)!=0) { - addApplicationRelationVO.add(getApplicationRelationVO(aggVO, childIVApplogVO, pk_ivapplication_split, pk_ivappdetail, iVApplicationBodyVO.getHh(), split_xmsl, split_xmje, split_xmjshj, splitMerge));//需要重新赋值的部分 + if (split_xmjshj.compareTo(UFDouble.ZERO_DBL) != 0) { + addApplicationRelationVO.add(getApplicationRelationVO(aggVO, childIVApplogVO, pk_ivapplication_split, pk_ivappdetail, iVApplicationBodyVO.getHh(), split_xmsl, split_xmje, split_xmjshj, splitMerge));// 需要重新赋值的部分 } - arr.getJSONObject(i).put(IVApplicationBodyVO.XMSL,UFDouble.ZERO_DBL.toBigDecimal()); - arr.getJSONObject(i).put(IVApplicationBodyVO.XMJE,UFDouble.ZERO_DBL.toBigDecimal()); - arr.getJSONObject(i).put(IVApplicationBodyVO.XMJSHJ,UFDouble.ZERO_DBL.toBigDecimal()); - arr.getJSONObject(i).put(IVApplicationBodyVO.SE,UFDouble.ZERO_DBL.toBigDecimal()); + arr.getJSONObject(i).put(IVApplicationBodyVO.XMSL, UFDouble.ZERO_DBL.toBigDecimal()); + arr.getJSONObject(i).put(IVApplicationBodyVO.XMJE, UFDouble.ZERO_DBL.toBigDecimal()); + arr.getJSONObject(i).put(IVApplicationBodyVO.XMJSHJ, UFDouble.ZERO_DBL.toBigDecimal()); + arr.getJSONObject(i).put(IVApplicationBodyVO.SE, UFDouble.ZERO_DBL.toBigDecimal()); split_xmjshj = UFDouble.ZERO_DBL; split_xmje = UFDouble.ZERO_DBL; split_xmsl = UFDouble.ZERO_DBL; update_arr.add(arr.getJSONObject(i)); - }else{ - //当前拆分金额部分用完 + } else { + // 当前拆分金额部分用完 split_xmjshj = split_xmjshj.sub(invoice_xmjshj); split_xmje = split_xmje.sub(invoice_xmje); split_xmsl = split_xmsl.sub(invoice_xmsl); - arr.getJSONObject(i).put(IVApplicationBodyVO.XMSL,split_xmsl.toBigDecimal()); - arr.getJSONObject(i).put(IVApplicationBodyVO.XMJE,split_xmje.toBigDecimal()); - arr.getJSONObject(i).put(IVApplicationBodyVO.XMJSHJ,split_xmjshj.toBigDecimal()); - arr.getJSONObject(i).put(IVApplicationBodyVO.SE,tranZeroAmount(split_xmjshj.sub(split_xmje)).toBigDecimal()); + arr.getJSONObject(i).put(IVApplicationBodyVO.XMSL, split_xmsl.toBigDecimal()); + arr.getJSONObject(i).put(IVApplicationBodyVO.XMJE, split_xmje.toBigDecimal()); + arr.getJSONObject(i).put(IVApplicationBodyVO.XMJSHJ, split_xmjshj.toBigDecimal()); + arr.getJSONObject(i).put(IVApplicationBodyVO.SE, tranZeroAmount(split_xmjshj.sub(split_xmje)).toBigDecimal()); update_arr.add(arr.getJSONObject(i)); - if(invoice_xmjshj.compareTo(UFDouble.ZERO_DBL)!=0) { - addApplicationRelationVO.add(getApplicationRelationVO(aggVO, childIVApplogVO, pk_ivapplication_split, pk_ivappdetail, iVApplicationBodyVO.getHh(), invoice_xmsl, invoice_xmje, invoice_xmjshj, splitMerge));//需要重新赋值的部分 + if (invoice_xmjshj.compareTo(UFDouble.ZERO_DBL) != 0) { + addApplicationRelationVO.add(getApplicationRelationVO(aggVO, childIVApplogVO, pk_ivapplication_split, pk_ivappdetail, iVApplicationBodyVO.getHh(), invoice_xmsl, invoice_xmje, invoice_xmjshj, splitMerge));// 需要重新赋值的部分 } invoice_xmjshj = UFDouble.ZERO_DBL; invoice_xmje = UFDouble.ZERO_DBL; @@ -590,9 +557,9 @@ public class InvoiceTransferUtil { } } iVApplicationBodyVO.setPk_ivappdetail(arr.toJSONString()); - }else{//非NCC拆分合并场景 - if(invoice_xmjshj.compareTo(UFDouble.ZERO_DBL)!=0) { - addApplicationRelationVO.add(getApplicationRelationVO(aggVO, childIVApplogVO, iVApplicationBodyVO.getPk_ivapplication(), iVApplicationBodyVO.getPk_ivappdetail(), iVApplicationBodyVO.getHh(), invoice_xmsl, invoice_xmje, invoice_xmjshj, splitMerge));//需要重新赋值的部分 + } else {// 非NCC拆分合并场景 + if (invoice_xmjshj.compareTo(UFDouble.ZERO_DBL) != 0) { + addApplicationRelationVO.add(getApplicationRelationVO(aggVO, childIVApplogVO, iVApplicationBodyVO.getPk_ivapplication(), iVApplicationBodyVO.getPk_ivappdetail(), iVApplicationBodyVO.getHh(), invoice_xmsl, invoice_xmje, invoice_xmjshj, splitMerge));// 需要重新赋值的部分 } } } @@ -603,47 +570,47 @@ public class InvoiceTransferUtil { } } - IVApplicationRelationVO[] oldApplicationRelationVO = NCLocator.getInstance().lookup(InvoiceSplitMergeService.class).saveSpiltAndMergeRelation(ivApplicationVOs,splitMerge,addApplicationRelationVO); - //2.3当前开票申请的票据与申请关联关系合集 - Set childApplicationRelationVOS =new HashSet(); - if(oldApplicationRelationVO!=null && oldApplicationRelationVO.length>0){ - for(IVApplicationRelationVO applicationRelationVO:oldApplicationRelationVO) { + IVApplicationRelationVO[] oldApplicationRelationVO = NCLocator.getInstance().lookup(InvoiceSplitMergeService.class).saveSpiltAndMergeRelation(ivApplicationVOs, splitMerge, addApplicationRelationVO); + // 2.3当前开票申请的票据与申请关联关系合集 + Set childApplicationRelationVOS = new HashSet(); + if (oldApplicationRelationVO != null && oldApplicationRelationVO.length > 0) { + for (IVApplicationRelationVO applicationRelationVO : oldApplicationRelationVO) { for (IVApplogVO childIVApplogVO : logs) { if (applicationRelationVO.getFpqqlsh().equals(childIVApplogVO.getLyid())) { - deleteApplicationRelationVO.add(applicationRelationVO);//需要清空删除的关联关系部分 + deleteApplicationRelationVO.add(applicationRelationVO);// 需要清空删除的关联关系部分 break; } } } } - //删除关联关系 - if(deleteApplicationRelationVO.size()>0){ + // 删除关联关系 + if (deleteApplicationRelationVO.size() > 0) { new IVApplicationRelationVODeleteBP().delete(deleteApplicationRelationVO.toArray(new IVApplicationRelationVO[deleteApplicationRelationVO.size()])); } - //更新关联关系 - if(addApplicationRelationVO.size()>0){ + // 更新关联关系 + if (addApplicationRelationVO.size() > 0) { new IVApplicationRelationVOInsertBP().insert(addApplicationRelationVO.toArray(new IVApplicationRelationVO[addApplicationRelationVO.size()])); } } return logs; } - public static IVApplicationRelationVO getApplicationRelationVO(IVApplicationAggVO aggVO, IVApplogVO childIVApplogVO,String pk_ivapplication, String pk_ivappdetail, String hh, UFDouble invoice_xmsl, UFDouble invoice_xmje, UFDouble invoice_xmjshj, boolean splitMerge) { + public static IVApplicationRelationVO getApplicationRelationVO(IVApplicationAggVO aggVO, IVApplogVO childIVApplogVO, String pk_ivapplication, String pk_ivappdetail, String hh, UFDouble invoice_xmsl, UFDouble invoice_xmje, UFDouble invoice_xmjshj, boolean splitMerge) { String kpfs = String.valueOf(aggVO.getParentVO().getKpfs());// 开票方式 1/直联开票、2/手工开票、3/发票拆分合并开票 IVApplicationRelationVO vo = new IVApplicationRelationVO(); vo.setPk_ivapplication(pk_ivapplication); vo.setPk_ivappdetail(pk_ivappdetail); - vo.setIsplitmerge(splitMerge?UFBoolean.TRUE:UFBoolean.FALSE); + vo.setIsplitmerge(splitMerge ? UFBoolean.TRUE : UFBoolean.FALSE); vo.setXmsl(invoice_xmsl); vo.setXmje(invoice_xmje); vo.setXmjshj(invoice_xmjshj); vo.setRowno(hh); - vo.setFpqqlsh(childIVApplogVO.getLyid());//税务云拆分的关联关系存储的是来源ID - vo.setPk_ivapplog(childIVApplogVO.getPk_ivapplog());//替换关联关系的生成,下游生成的部分会替换并按行赋值。便于找到回退的数据 - if(IVAWebConst.IVA_KP_SSCIVA01_1.equals(kpfs) || splitMerge) { - vo.setKpfs(IVAplocationKPFS.ZLKP.toIntValue());//直连开票 - }else{ - vo.setKpfs(IVAplocationKPFS.SGKP.toIntValue());//手工开票 + vo.setFpqqlsh(childIVApplogVO.getLyid());// 税务云拆分的关联关系存储的是来源ID + vo.setPk_ivapplog(childIVApplogVO.getPk_ivapplog());// 替换关联关系的生成,下游生成的部分会替换并按行赋值。便于找到回退的数据 + if (IVAWebConst.IVA_KP_SSCIVA01_1.equals(kpfs) || splitMerge) { + vo.setKpfs(IVAplocationKPFS.ZLKP.toIntValue());// 直连开票 + } else { + vo.setKpfs(IVAplocationKPFS.SGKP.toIntValue());// 手工开票 } return vo; } @@ -679,7 +646,7 @@ public class InvoiceTransferUtil { logvo.setInvoice_type(String.valueOf(applyvo.getParentVO().getFplx())); logvo.setGmfmc(applyvo.getParentVO().getGmf_mc()); logvo.setXsfmc(applyvo.getParentVO().getXsf_mc()); - if (applyvo.getHeadVO().getSgbz()!=null && applyvo.getHeadVO().getSgbz().booleanValue()) { + if (applyvo.getHeadVO().getSgbz() != null && applyvo.getHeadVO().getSgbz().booleanValue()) { logvo.setGmfmc(applyvo.getParentVO().getXsf_mc()); logvo.setXsfmc(applyvo.getParentVO().getGmf_mc()); } @@ -732,7 +699,7 @@ public class InvoiceTransferUtil { head.setViewurl(null); head.setBillstatus(IBillStatus.CHECKPASS); - //数电特殊票种 + // 数电特殊票种 head.setZsfs(pinvoice.getZsfs()); head.setTspz(IVApplicationTspzUtil.getTspzPk(pinvoice.getTspz())); head.setTspzdef99(head.getTspz()); @@ -783,11 +750,11 @@ public class InvoiceTransferUtil { head.setYlzfphm(ivApplicationHeadVO.getFphm()); } // 重新查询交易类型 - IUAPQueryBS iUAPQueryBS = (IUAPQueryBS)NCLocator.getInstance().lookup(IUAPQueryBS.class.getName()); - if (ivApplicationHeadVO.getSgbz()!=null && ivApplicationHeadVO.getSgbz().booleanValue()) { + IUAPQueryBS iUAPQueryBS = (IUAPQueryBS) NCLocator.getInstance().lookup(IUAPQueryBS.class.getName()); + if (ivApplicationHeadVO.getSgbz() != null && ivApplicationHeadVO.getSgbz().booleanValue()) { @SuppressWarnings("unchecked") List vos = - (List)iUAPQueryBS.retrieveByClause(BilltypeVO.class, BilltypeVO.PK_BILLTYPECODE + (List) iUAPQueryBS.retrieveByClause(BilltypeVO.class, BilltypeVO.PK_BILLTYPECODE + "='SSIV-Cxx-rec' " + " AND " + " pk_group ='" + ivApplicationHeadVO.getPk_group() + "' "); if (vos != null && vos.size() > 0) { String pk_billtypeid = vos.get(0).getPk_billtypeid(); @@ -797,16 +764,16 @@ public class InvoiceTransferUtil { head.setPk_billtype(IVAWebConst.IVA_JXFP_JYLXPK);// 交易类型主键 head.setBilltypecode(IVAWebConst.IVA_JXFP_JYLXBM); } - //收票日期 NC系统日期 + // 收票日期 NC系统日期 head.setSprq(new UFDate()); - //收票人取开票申请修改人 + // 收票人取开票申请修改人 head.setSpr(ivApplicationHeadVO.getModifier()); - //收购标志 + // 收购标志 head.setSgbz(UFBoolean.TRUE); - //默认为采购类发票 + // 默认为采购类发票 head.setClasstype(ClassTypeEnum.ClassType_CGL.toIntValue()); - //收购发票,购销信息对调 + // 收购发票,购销信息对调 head.setXsfmc(pinvoice.getGmfMc()); head.setXsfnsrsbh(pinvoice.getGmfNsrsbh()); head.setXsfdzdh(pinvoice.getGmfDzdh()); @@ -818,7 +785,7 @@ public class InvoiceTransferUtil { } else { @SuppressWarnings("unchecked") List vos = - (List)iUAPQueryBS.retrieveByClause(BilltypeVO.class, BilltypeVO.PK_BILLTYPECODE + (List) iUAPQueryBS.retrieveByClause(BilltypeVO.class, BilltypeVO.PK_BILLTYPECODE + "='SSIV-Cxx-sale' " + " AND " + " pk_group ='" + ivApplicationHeadVO.getPk_group() + "' "); if (vos != null && vos.size() > 0) { String pk_billtypeid = vos.get(0).getPk_billtypeid(); @@ -828,7 +795,7 @@ public class InvoiceTransferUtil { head.setPk_billtype(IVAWebConst.IVA_XXFP_JYLXPK);// 交易类型主键 head.setBilltypecode(IVAWebConst.IVA_XXFP_JYLXBM); } - //非收购发票,购销信息直传 + // 非收购发票,购销信息直传 head.setXsfmc(pinvoice.getXsfMc()); head.setXsfnsrsbh(pinvoice.getXsfNsrsbh()); head.setXsfdzdh(pinvoice.getXsfDzdh()); @@ -872,9 +839,9 @@ public class InvoiceTransferUtil { detail.setIsfee(UFBoolean.FALSE); detail.setFphxz(Integer.valueOf(item.getFphxz())); detail.setZkhhh(item.getZkhhh()); - //数电特殊票种 + // 数电特殊票种 PInvoiceSDetail motor = item.getDetailMotor(); - if(motor != null){ + if (motor != null) { detail.setJzfwfsd(motor.getJzfwfsd()); detail.setJzxmmc(motor.getJzxmmc()); detail.setCqzsbh(motor.getCqzsbh()); @@ -883,13 +850,13 @@ public class InvoiceTransferUtil { } } - //特殊票种 + // 特殊票种 List tspzDetails = new ArrayList(); - if (pinvoice.getTspzs() != null && pinvoice.getTspzs().length > 0){ - for (PInvoiceTspz ptspz : pinvoice.getTspzs()){ - IVMInvoiceTspzDetailVO tspz = new IVMInvoiceTspzDetailVO(); + if (pinvoice.getTspzs() != null && pinvoice.getTspzs().length > 0) { + for (PInvoiceTspz ptspz : pinvoice.getTspzs()) { + IVMInvoiceTspzDetailVO tspz = new IVMInvoiceTspzDetailVO(); - //货运 + // 货运 tspz.setYsmxxh(ptspz.getYsmxxh()); tspz.setYsgjzl(ptspz.getYsgjzl()); tspz.setYsgjph(ptspz.getYsgjph()); @@ -897,7 +864,7 @@ public class InvoiceTransferUtil { tspz.setDdd(ptspz.getDdd()); tspz.setYshwmc(ptspz.getYshwmc()); - //客运 + // 客运 tspz.setCxrxh(ptspz.getCxrxh()); tspz.setCxr(ptspz.getCxr()); tspz.setChuxrq(ptspz.getChuxrq() == null ? null : getUFDate(ptspz.getChuxrq())); @@ -912,8 +879,8 @@ public class InvoiceTransferUtil { } } - if (pinvoice.getCepzs() != null && pinvoice.getCepzs().length > 0){ - for (PInvoiceCepz pcepz : pinvoice.getCepzs()){ + if (pinvoice.getCepzs() != null && pinvoice.getCepzs().length > 0) { + for (PInvoiceCepz pcepz : pinvoice.getCepzs()) { IVMInvoiceTspzDetailVO cepz = new IVMInvoiceTspzDetailVO(); cepz.setXh(pcepz.getXh()); cepz.setPzlx(pcepz.getPzlx()); @@ -936,7 +903,7 @@ public class InvoiceTransferUtil { aggvo.setParentVO(head); aggvo.setChildrenVO(details.toArray(new IVMInvoiceDetailVO[0])); - if (tspzDetails.size() > 0){ + if (tspzDetails.size() > 0) { aggvo.setIvmInvoiceTspzDetailVO(tspzDetails.toArray(new IVMInvoiceTspzDetailVO[0])); } @@ -946,7 +913,7 @@ public class InvoiceTransferUtil { private static void initKhcje(IVMInvoiceAggVO aggvo) { IVMInvoiceHeadVO head = aggvo.getParentVO(); - if(head.getRed_flag() != null && head.getRed_flag().intValue() != IsHzfp.IsHzfp_0.toIntValue()){ + if (head.getRed_flag() != null && head.getRed_flag().intValue() != IsHzfp.IsHzfp_0.toIntValue()) { return; } // 1. 初始化表头可红冲金额等于价税合计金额 @@ -955,7 +922,7 @@ public class InvoiceTransferUtil { head.setYhcje(UFDouble.ZERO_DBL); // 2. 初始化表体可红冲金额 - IVMInvoiceDetailVO[] detailVOs = (IVMInvoiceDetailVO[])aggvo.getChildrenVO(); + IVMInvoiceDetailVO[] detailVOs = (IVMInvoiceDetailVO[]) aggvo.getChildrenVO(); Map rowNumAndJshjMap = new HashMap<>(); for (IVMInvoiceDetailVO detail : detailVOs) { rowNumAndJshjMap.put(detail.getRowno(), detail.getXmjshj()); @@ -990,33 +957,33 @@ public class InvoiceTransferUtil { if (lyids != null) { List bhcInvoiceRelations = new ArrayList(); Map billRelationMap = new HashMap(); - //红字发票,根据原蓝票回写金额需要提前 + // 红字发票,根据原蓝票回写金额需要提前 boolean hzfp = "1".equals(String.valueOf(pinvoice.getParentVO().getRed_flag())); - if(hzfp) { - //查询被红冲的发票的发票单据关联关系,丢失的关系直接从其中补 - StringBuilder queryReSql = new StringBuilder(""); + if (hzfp) { + // 查询被红冲的发票的发票单据关联关系,丢失的关系直接从其中补 + StringBuilder queryReSql = new StringBuilder(""); queryReSql.append(" select ion.* from sscivm_invoice_relation ion "); queryReSql.append(" left join sscivm_invoice ice on ion.pk_invoice = ice.pk_invoice "); - queryReSql.append(" where ion.fphm = '"+pinvoice.getParentVO().getYlzfphm()+"' "); - if (pinvoice.getParentVO().getYlzfpdm() != null){ - queryReSql.append(" and ion.fpdm = '"+pinvoice.getParentVO().getYlzfpdm()+"' "); + queryReSql.append(" where ion.fphm = '" + pinvoice.getParentVO().getYlzfphm() + "' "); + if (pinvoice.getParentVO().getYlzfpdm() != null) { + queryReSql.append(" and ion.fpdm = '" + pinvoice.getParentVO().getYlzfpdm() + "' "); } queryReSql.append(" and ice.dr = 0 "); queryReSql.append(" and (ice.billtypecode ='SSIV-Cxx-sale' or (ice.billtypecode ='SSIV-Cxx-rec' and ice.invoice_type in (109,309))) "); bhcInvoiceRelations = (List) new BaseDAO().executeQuery(queryReSql.toString(), new BeanListProcessor(IVMInvoiceRelationVO.class)); - if(bhcInvoiceRelations.size()>0) { + if (bhcInvoiceRelations.size() > 0) { for (IVMInvoiceRelationVO bhcInvoiceRelation : bhcInvoiceRelations) { billRelationMap.put(bhcInvoiceRelation.getBillid(), bhcInvoiceRelation); } - //业务单据红冲不记录关联关系 + // 业务单据红冲不记录关联关系 boolean ywdjhc = true; - for (IVApplicationAggVO ivApplicationHeadVO : ivApplicationHeadVOS){ - if (billRelationMap.containsKey(ivApplicationHeadVO.getParentVO().getSrc_pkbusibill())){ + for (IVApplicationAggVO ivApplicationHeadVO : ivApplicationHeadVOS) { + if (billRelationMap.containsKey(ivApplicationHeadVO.getParentVO().getSrc_pkbusibill())) { ywdjhc = false; } } - if (ywdjhc){ + if (ywdjhc) { billRelationMap = new HashMap(); bhcInvoiceRelations = new ArrayList(); } @@ -1031,8 +998,8 @@ public class InvoiceTransferUtil { if (ivApplicationHeadVO.getParentVO().getCkfp() != null && ivApplicationHeadVO.getParentVO().getCkfp().booleanValue()) { - //查找原发票的发票单据关联关系,从中补关系 - StringBuilder queryReSql = new StringBuilder(""); + // 查找原发票的发票单据关联关系,从中补关系 + StringBuilder queryReSql = new StringBuilder(""); queryReSql.append(" select rel.* from sscivm_invoice_relation rel "); queryReSql.append(" left join sscivm_invoice ice on rel.pk_invoice = ice.pk_invoice "); queryReSql.append(" left join sscivm_ivapplication iva on (iva.pk_ivapplication ='"); @@ -1047,11 +1014,11 @@ public class InvoiceTransferUtil { List yInvoiceRelations = (List) new BaseDAO() .executeQuery(queryReSql.toString(), new BeanListProcessor(IVMInvoiceRelationVO.class)); - //根据原发票的发票关联关系,生成 发票关联关系 - if(yInvoiceRelations.size()>0) { + // 根据原发票的发票关联关系,生成 发票关联关系 + if (yInvoiceRelations.size() > 0) { for (IVMInvoiceRelationVO bhcInvoiceRelation : yInvoiceRelations) { billRelationMap.put(bhcInvoiceRelation.getBillid(), bhcInvoiceRelation); - if(StringUtils.isBlank(bhcInvoiceRelation.getBillid()) || bhcInvoiceRelation.getBillid().equals(ivApplicationHeadVO.getParentVO().getSrc_pkbusibill())){ + if (StringUtils.isBlank(bhcInvoiceRelation.getBillid()) || bhcInvoiceRelation.getBillid().equals(ivApplicationHeadVO.getParentVO().getSrc_pkbusibill())) { continue; } IVMInvoiceRelationVO head = new IVMInvoiceRelationVO(); @@ -1085,7 +1052,7 @@ public class InvoiceTransferUtil { if (lyidstr != null && map.get(lyidstr).contains(ivApplicationHeadVO.getParentVO().getPk_ivapplication())) { IVMInvoiceRelationVO head = new IVMInvoiceRelationVO(); head.setStatus(VOStatus.NEW); - if(StringUtils.isBlank(ivApplicationHeadVO.getParentVO().getSrc_pkbusibill())){ + if (StringUtils.isBlank(ivApplicationHeadVO.getParentVO().getSrc_pkbusibill())) { continue; } // 票面信息 @@ -1098,15 +1065,15 @@ public class InvoiceTransferUtil { head.setInvoiceamount(pinvoice.getParentVO().getJshj()); head.setPk_invoice(pinvoice.getParentVO().getPk_invoice()); IVMInvoiceRelationVO oldvo = billRelationMap.get(head.getBillid()); - if(oldvo != null){ - if(hzfp){ - if(oldvo.getAmount() != null){ + if (oldvo != null) { + if (hzfp) { + if (oldvo.getAmount() != null) { head.setAmount(oldvo.getAmount().multiply(-1)); } - if(oldvo.getJe() != null){ + if (oldvo.getJe() != null) { head.setJe(oldvo.getJe().multiply(-1)); } - if(oldvo.getSe() != null){ + if (oldvo.getSe() != null) { head.setSe(oldvo.getSe().multiply(-1)); } } else { @@ -1116,26 +1083,29 @@ public class InvoiceTransferUtil { } } heads.add(head); - if(ivApplicationHeadVO.getParentVO().getSrc_pkbusibill()!=null && ivApplicationHeadVO.getParentVO().getSrc_pkbusibill().length()>0) { - pk_ivapplicationSet.add(ivApplicationHeadVO.getParentVO().getSrc_pkbusibill());} + if (ivApplicationHeadVO.getParentVO().getSrc_pkbusibill() != null && ivApplicationHeadVO.getParentVO().getSrc_pkbusibill().length() > 0) { + pk_ivapplicationSet.add(ivApplicationHeadVO.getParentVO().getSrc_pkbusibill()); + } } } } - //合并场景联查对应的红字发票相关单据 - if(hzfp && pk_ivapplicationSet.size()>0) { - //根据被红冲发票关联关系,生成 发票关联关系 - if(bhcInvoiceRelations.size()>0) { + // 合并场景联查对应的红字发票相关单据 + if (hzfp && pk_ivapplicationSet.size() > 0) { + // 根据被红冲发票关联关系,生成 发票关联关系 + if (bhcInvoiceRelations.size() > 0) { for (IVMInvoiceRelationVO bhcInvoiceRelation : bhcInvoiceRelations) { IVMInvoiceRelationVO head = new IVMInvoiceRelationVO(); boolean continueAdd = true; - for(IVMInvoiceRelationVO headin:heads) { - if(headin.getBillid() != null && bhcInvoiceRelation.getBillid() != null && headin.getBillid().equals(bhcInvoiceRelation.getBillid())) { - continueAdd =false; + for (IVMInvoiceRelationVO headin : heads) { + if (headin.getBillid() != null && bhcInvoiceRelation.getBillid() != null && headin.getBillid().equals(bhcInvoiceRelation.getBillid())) { + continueAdd = false; } } - if(!continueAdd) { continue;} + if (!continueAdd) { + continue; + } head.setStatus(VOStatus.NEW); // 票面信息 head.setFphm(pinvoice.getParentVO().getFphm()); @@ -1189,12 +1159,13 @@ public class InvoiceTransferUtil { /** * 根据发票生成开票日志 + * * @param pinvoice * @param kpzt * @return * @throws BusinessException */ - public static IVApplogVO getIVApplogVOFromPInvoice(PInvoice pinvoice, int kpzt) throws BusinessException{ + public static IVApplogVO getIVApplogVOFromPInvoice(PInvoice pinvoice, int kpzt) throws BusinessException { SequenceGenerator generator = new SequenceGenerator(); IVApplogVO logvo = new IVApplogVO(); logvo.setCode(IVMInvoiceConstant.SUCCESS_CODE); @@ -1273,11 +1244,11 @@ public class InvoiceTransferUtil { pinvoice.setLyid(headvo.getPk_ivapplication()); pinvoice.setFplx(InvoiceTypeToTspzUtil.getRealInvoicetype(headvo.getFplx())); String tspz = InvoiceTypeToTspzUtil.getTspz(headvo.getFplx()); - if(StringUtils.isEmpty(tspz) && StringUtils.isNotEmpty(headvo.getTspz())){ + if (StringUtils.isEmpty(tspz) && StringUtils.isNotEmpty(headvo.getTspz())) { try { - Collection defdocVOS = ((IUAPQueryBS)NCLocator.getInstance().lookup(IUAPQueryBS.class.getName())).retrieveByClause(DefdocVO.class, " "+DefdocVO.PK_DEFDOC+"='"+headvo.getTspz()+"' "); - if(defdocVOS!=null && defdocVOS.size()>0){ - for(DefdocVO DefdocVO:defdocVOS){ + Collection defdocVOS = ((IUAPQueryBS) NCLocator.getInstance().lookup(IUAPQueryBS.class.getName())).retrieveByClause(DefdocVO.class, " " + DefdocVO.PK_DEFDOC + "='" + headvo.getTspz() + "' "); + if (defdocVOS != null && defdocVOS.size() > 0) { + for (DefdocVO DefdocVO : defdocVOS) { tspz = DefdocVO.getCode(); break; } @@ -1289,7 +1260,7 @@ public class InvoiceTransferUtil { pinvoice.setTspz(tspz); // 目前传值,后续应该不传,税务云都通过组织编码解析,销售方的其他信息不需要传值 - if (headvo.getSgbz()!=null && headvo.getSgbz().booleanValue()) {//收购销方转购方 + if (headvo.getSgbz() != null && headvo.getSgbz().booleanValue()) {// 收购销方转购方 pinvoice.setGmf_dz(headvo.getXsf_dz()); pinvoice.setGmf_dh(headvo.getXsf_dh()); pinvoice.setGmf_yh(headvo.getXsf_yh()); @@ -1300,7 +1271,7 @@ public class InvoiceTransferUtil { pinvoice.setGmfYhzh(headvo.getXsf_yhzh()); pinvoice.setXsfNsrsbh(headvo.getGmf_nsrsbh()); } else { - pinvoice.setXsfYhzh((headvo.getXsf_yhzh()==null?"":headvo.getXsf_yhzh())); + pinvoice.setXsfYhzh((headvo.getXsf_yhzh() == null ? "" : headvo.getXsf_yhzh())); pinvoice.setXsfNsrsbh(headvo.getXsf_nsrsbh()); pinvoice.setXsf_dz(headvo.getXsf_dz()); pinvoice.setXsf_dh(headvo.getXsf_dh()); @@ -1316,7 +1287,7 @@ public class InvoiceTransferUtil { pinvoice.setGmfYhzh(headvo.getGmf_yhzh()); } - //收购标志处理 + // 收购标志处理 if (headvo.getSgbz().booleanValue()) { pinvoice.setSgbz("2"); } @@ -1335,15 +1306,15 @@ public class InvoiceTransferUtil { pinvoice.setZdybz(headvo.getZdybz()); pinvoice.setOrgcode(headvo.getOrgcode()); - //税率说明 + // 税率说明 pinvoice.setSlsm(headvo.getSlsm()); pinvoice.setAllelcusername(headvo.getAllelcusername()); pinvoice.setAllelcpassword(headvo.getAllelcpassword()); - pinvoice.setZsfs(headvo.getZsfs()==null?"":headvo.getZsfs()); + pinvoice.setZsfs(headvo.getZsfs() == null ? "" : headvo.getZsfs()); - //数电特殊票种字段 + // 数电特殊票种字段 pinvoice.setBdcdz(headvo.getBdcdz()); pinvoice.setZlqq(getFormatDate(headvo.getZlqq())); pinvoice.setZlqz(getFormatDate(headvo.getZlqz())); @@ -1360,10 +1331,51 @@ public class InvoiceTransferUtil { pinvoice.setZnj(headvo.getZnj() == null ? null : getUFDoubleToBigDecimal(headvo.getZnj()).setScale(2, UFDouble.ROUND_HALF_UP)); pinvoice.setJehj(headvo.getJehj() == null ? null : getUFDoubleToBigDecimal(headvo.getJehj()).setScale(2, UFDouble.ROUND_HALF_UP)); pinvoice.setCjh(headvo.getCjh()); -// pinvoice.setKqysssxbgglbm(headvo.getKqysssxbgglbm()); + // pinvoice.setKqysssxbgglbm(headvo.getKqysssxbgglbm()); + + setOtherField(headvo, pinvoice); return pinvoice; } + private static void setOtherField(IVApplicationHeadVO headvo, PInvoice pinvoice) { + // 是否展示销售方开户银行及账号 Y-是/N-否 + String def3 = headvo.getDef3(); + // 是否展示销售方地址电话 + String def4 = headvo.getDef4(); + // 是否填写收款人及复核人 + String def16 = headvo.getDef16(); + // 是否展示购买方单位、地址电话 + String def17 = headvo.getDef17(); + // 是否展示购买方开户行、银行账号 + String def18 = headvo.getDef18(); + + // einvoiceShowGxfDzDh 表示是否显示购方和销方的地址电话 + // 根据需求:0: 不显示 1: 显示购方地址电话 2: 显示销方地址电话 3: 显示购方和销方地址电话 + int einvoiceShowGxfDzDh = 0; + + if ("Y".equals(def3)) { + einvoiceShowGxfDzDh += 1; // 购方地址电话显示 + } + if ("Y".equals(def17)) { + einvoiceShowGxfDzDh += 2; // 销方地址电话显示 + } + + // einvoiceShowGxfYhZh 表示是否显示购方和销方的小银行账户 + // 根据需求:0: 不显示 1: 显示购方银行账户 2: 显示销方银行账户 3: 显示购方和销方银行账户 + int einvoiceShowGxfYhZh = 0; + + if ("Y".equals(def4)) { + einvoiceShowGxfYhZh += 1; // 购方银行账户显示 + } + if ("Y".equals(def18)) { + einvoiceShowGxfYhZh += 2; // 销方银行账户显示 + } + // 数电发票是否显示购销方地址电话 0:不显示 1:仅显示销地址、电话 2:仅显示购买方地址、电话 3:购销方地址、电话都显示 + pinvoice.setEinvoiceShowGxfDzDh(String.valueOf(einvoiceShowGxfDzDh)); + // 数电发票是否显示购销方银行、账号: 0:不显示 1:仅显示销售方银行、账号 2:仅显示购买方银行、账号 3:购销方银行、账号都显示 + pinvoice.setEinvoiceShowGxfYhZh(String.valueOf(einvoiceShowGxfYhZh)); + } + /** * 根据红冲申请转换成发票平台VO * @@ -1380,7 +1392,7 @@ public class InvoiceTransferUtil { pinvoice.setFpDm(headvo.getFpdm()); pinvoice.setKpr(headvo.getKpr()); pinvoice.setJshj(getUFDoubleToBigDecimal(headvo.getCaninvoice_jshj()).setScale(2, UFDouble.ROUND_HALF_UP)); - pinvoice.setXsfYhzh((headvo.getXsf_yhzh()==null?"":headvo.getXsf_yhzh())); + pinvoice.setXsfYhzh((headvo.getXsf_yhzh() == null ? "" : headvo.getXsf_yhzh())); pinvoice.setHzxxbbh(headvo.getHzxxsqb()); // pinvoice.setHjje(getUFDoubleToBigDecimal(headvo.getHjje()).setScale(2, // UFDouble.ROUND_HALF_UP));//存在含税和不含税单价,统一交由税务云反算 @@ -1388,7 +1400,7 @@ public class InvoiceTransferUtil { // UFDouble.ROUND_HALF_UP));//存在含税和不含税单价,统一交由税务云反算 pinvoice.setOrgcode(headvo.getOrgcode()); - //税率说明红冲原因 + // 税率说明红冲原因 pinvoice.setSlsm(headvo.getSlsm()); pinvoice.setHcyy(headvo.getHcyy()); @@ -1410,8 +1422,8 @@ public class InvoiceTransferUtil { private static PInvoiceDetail getPInvoiceByApplyHead(IVApplicationHeadVO headvo, IVApplicationBodyVO body) { PInvoiceDetail detailvo = new PInvoiceDetail(); - //开票神申请规格型号自动截取40位长度 - detailvo.setGgxh((body.getGgxh()!=null&&body.getGgxh().length()>40)?body.getGgxh().substring(0, 40):body.getGgxh()); + // 开票神申请规格型号自动截取40位长度 + detailvo.setGgxh((body.getGgxh() != null && body.getGgxh().length() > 40) ? body.getGgxh().substring(0, 40) : body.getGgxh()); detailvo.setDw(body.getDw()); detailvo.setXmsl(getUFDoubleToBigDecimal(body.getCaninvoice_xmsl())); detailvo.setZkhhh(body.getZkhhh()); @@ -1422,14 +1434,14 @@ public class InvoiceTransferUtil { detailvo.setXmjshj(getUFDoubleToBigDecimal(body.getCaninvoice_xmjshj()).setScale(2, UFDouble.ROUND_HALF_UP)); detailvo.setSl(getUFDoubleToBigDecimal(body.getSl()).multiply(new BigDecimal(0.01))); // detailvo.setSe(detailvo.getXmjshj().subtract(detailvo.getXmje())); //税务云反算 - if(body.getSsflbm()!=null && body.getSsflbm().length()>0){ + if (body.getSsflbm() != null && body.getSsflbm().length() > 0) { // 传税收分类编码的开票 detailvo.setSpbm(body.getSsflbm()); detailvo.setXmmc(body.getXmmc()); - }else if ((body.getPk_materiel() == null || body.getPk_materiel().length() == 0)) { + } else if ((body.getPk_materiel() == null || body.getPk_materiel().length() == 0)) { // 重开的场景 String xmmc = body.getXmmc(); - if (xmmc != null && headvo.getCkfp() != null && headvo.getCkfp().booleanValue()) { + if (xmmc != null && headvo.getCkfp() != null && headvo.getCkfp().booleanValue()) { xmmc = xmmc.replace("*", "");// 按税务云清除第一个*号 xmmc = xmmc.replace("*", "");// 按税务云清除第二个*号 } @@ -1444,60 +1456,60 @@ public class InvoiceTransferUtil { if (headvo.getSgbz().booleanValue()) { detailvo.setLslbs(IVAplocationLSLBS.LSLBS_MS.toStringValue()); } - if(body.getYhzcbs()!=null){ + if (body.getYhzcbs() != null) { detailvo.setYhzcbs(body.getYhzcbs()); detailvo.setZzstsgl(body.getZzstsgl()); } detailvo.setKce(body.getKce() == null ? null : getUFDoubleToBigDecimal(body.getKce())); - //简易征收 + // 简易征收 if (body.getYhzcbs() != null) { detailvo.setYhzcbs(body.getYhzcbs()); } detailvo.setZzstsgl(body.getZzstsgl()); - //motor 明细数据处理 + // motor 明细数据处理 PInvoiceSDetail motor = new PInvoiceSDetail(); motor.setCqzsbh(body.getCqzsbh()); motor.setJzfwfsd(body.getJzfwfsd()); motor.setJzxmmc(body.getJzxmmc()); // **************************2024-07-10 新增 对应税务云,开票申请表体增加9个自定义项 - if(!StringUtils.isEmpty(body.getDef24())) {//CD 产地 + if (!StringUtils.isEmpty(body.getDef24())) {// CD 产地 motor.setCd(body.getDef24()); } - if(!StringUtils.isEmpty(body.getDef25())) {//CJHM 车架号码! + if (!StringUtils.isEmpty(body.getDef25())) {// CJHM 车架号码! motor.setCjhm(body.getDef25()); } - if(!StringUtils.isEmpty(body.getDef26())) {//车辆类型 CLLX + if (!StringUtils.isEmpty(body.getDef26())) {// 车辆类型 CLLX motor.setCllx(body.getDef26()); } - if(!StringUtils.isEmpty(body.getDef27())) {//CPXH 厂牌型号 + if (!StringUtils.isEmpty(body.getDef27())) {// CPXH 厂牌型号 motor.setCpxh(body.getDef27()); } - if(!StringUtils.isEmpty(body.getDef28())) {//SCQYMC 生产企业名称 + if (!StringUtils.isEmpty(body.getDef28())) {// SCQYMC 生产企业名称 motor.setScqymc(body.getDef28()); } - if(!StringUtils.isEmpty(body.getDef29())) {// XCRS 限乘人数 + if (!StringUtils.isEmpty(body.getDef29())) {// XCRS 限乘人数 motor.setXcrs(body.getDef29()); } - if(!StringUtils.isEmpty(body.getDef17())) {// HGZH 合格证号 + if (!StringUtils.isEmpty(body.getDef17())) {// HGZH 合格证号 motor.setHgzh(body.getDef17()); } - if(!StringUtils.isEmpty(body.getDef17())) {// HGZH 合格证号 + if (!StringUtils.isEmpty(body.getDef17())) {// HGZH 合格证号 motor.setHgzh(body.getDef17()); } - if(!StringUtils.isEmpty(body.getDef20())) {// FDJHM 发动机号码 + if (!StringUtils.isEmpty(body.getDef20())) {// FDJHM 发动机号码 motor.setFdjhm(body.getDef20()); } - if(!StringUtils.isEmpty(body.getDef30())) {// DUNWEI 吨位 + if (!StringUtils.isEmpty(body.getDef30())) {// DUNWEI 吨位 motor.setDunwei(body.getDef30()); } @@ -1509,6 +1521,7 @@ public class InvoiceTransferUtil { /** * 特殊票种发票信息转换 + * * @param tspzVOs * @param invoice * @return @@ -1516,9 +1529,9 @@ public class InvoiceTransferUtil { private static PInvoice getPInvoiceByApplyTspz(IVTspzsBodyVO[] tspzVOs, PInvoice invoice) { List tspzs = new ArrayList(); List cepzs = new ArrayList(); - for (IVTspzsBodyVO tspzVO : tspzVOs){ - //差额开票 - if (StringUtils.isNotEmpty(tspzVO.getPzlx()) && (IVAplocationZSFS.HCYY_CEZS.toStringValue().equals(invoice.getZsfs())|| IVAplocationZSFS.HCYY_QEZS.toStringValue().equals(invoice.getZsfs()))){ + for (IVTspzsBodyVO tspzVO : tspzVOs) { + // 差额开票 + if (StringUtils.isNotEmpty(tspzVO.getPzlx()) && (IVAplocationZSFS.HCYY_CEZS.toStringValue().equals(invoice.getZsfs()) || IVAplocationZSFS.HCYY_QEZS.toStringValue().equals(invoice.getZsfs()))) { PInvoiceCepz cepz = new PInvoiceCepz(); cepz.setXh(tspzVO.getXh()); cepz.setPzlx(tspzVO.getPzlx()); @@ -1536,8 +1549,8 @@ public class InvoiceTransferUtil { cepzs.add(cepz); } - //货物运输 - if (StringUtils.isNotEmpty(tspzVO.getYsgjzl()) && IVAWebConst.TSPZ_HWYS.equals(invoice.getTspz())){ + // 货物运输 + if (StringUtils.isNotEmpty(tspzVO.getYsgjzl()) && IVAWebConst.TSPZ_HWYS.equals(invoice.getTspz())) { PInvoiceTspz tspz = new PInvoiceTspz(); tspz.setYsmxxh(tspzVO.getYsmxxh()); tspz.setYsgjzl(tspzVO.getYsgjzl()); @@ -1548,8 +1561,8 @@ public class InvoiceTransferUtil { tspzs.add(tspz); } - //旅客运输 - if (StringUtils.isNotEmpty(tspzVO.getCxr()) && IVAWebConst.TSPZ_LKYS.equals(invoice.getTspz())){ + // 旅客运输 + if (StringUtils.isNotEmpty(tspzVO.getCxr()) && IVAWebConst.TSPZ_LKYS.equals(invoice.getTspz())) { PInvoiceTspz tspz = new PInvoiceTspz(); tspz.setCxrxh(tspzVO.getCxrxh()); tspz.setCxr(tspzVO.getCxr()); @@ -1564,10 +1577,10 @@ public class InvoiceTransferUtil { } } - if (tspzs.size() > 0){ + if (tspzs.size() > 0) { invoice.setTspzs(tspzs.toArray(new PInvoiceTspz[0])); } - if (cepzs.size() > 0){ + if (cepzs.size() > 0) { invoice.setCepzs(cepzs.toArray(new PInvoiceCepz[0])); } return invoice; @@ -1584,8 +1597,8 @@ public class InvoiceTransferUtil { PInvoiceDetail detailvo = new PInvoiceDetail(); detailvo.setXmmc(body.getXmmc()); - //开票神申请规格型号自动截取40位长度 - detailvo.setGgxh((body.getGgxh()!=null&&body.getGgxh().length()>40)?body.getGgxh().substring(0, 40):body.getGgxh()); + // 开票神申请规格型号自动截取40位长度 + detailvo.setGgxh((body.getGgxh() != null && body.getGgxh().length() > 40) ? body.getGgxh().substring(0, 40) : body.getGgxh()); detailvo.setDw(body.getDw()); detailvo.setXmsl(getUFDoubleToBigDecimal(body.getCaninvoice_xmsl())); detailvo.setZkhhh(body.getZkhhh()); @@ -1596,10 +1609,10 @@ public class InvoiceTransferUtil { detailvo.setXmjshj(getUFDoubleToBigDecimal(body.getCaninvoice_xmjshj()).setScale(2, UFDouble.ROUND_HALF_UP)); detailvo.setSl(getUFDoubleToBigDecimal(body.getSl()).multiply(new BigDecimal(0.01))); // detailvo.setSe(getUFDoubleToBigDecimal(body.getSe()));//存在含税和不含税单价,统一交由税务云反算 - if(body.getSsflbm()!=null && body.getSsflbm().length()>0){ + if (body.getSsflbm() != null && body.getSsflbm().length() > 0) { // 传税收分类编码的开票 detailvo.setSpbm(body.getSsflbm()); - }else { + } else { detailvo.setSpbm(body.getSpbm()); } return detailvo; @@ -1636,15 +1649,16 @@ public class InvoiceTransferUtil { /** * 获取开票日期 + * * @param kprq 税务云传递过来的开票日期 * @return UFDate 转换后的开票日期 */ - public static UFDate getUFDate(String kprq){ - //日期为空或长度不对,直接取当前日期 - if(kprq != null && kprq.length() == 10) { + public static UFDate getUFDate(String kprq) { + // 日期为空或长度不对,直接取当前日期 + if (kprq != null && kprq.length() == 10) { return new UFDate(kprq); } - if (kprq == null || kprq.length() != 14){ + if (kprq == null || kprq.length() != 14) { return new UFDate(); } else { StringBuffer date = new StringBuffer(); @@ -1665,9 +1679,11 @@ public class InvoiceTransferUtil { public static UFDouble tranZeroAmount(UFDouble amount) { - if(amount==null) {return UFDouble.ZERO_DBL;} - amount = (amount.compareTo(UFDouble.ZERO_DBL)<0)?UFDouble.ZERO_DBL:amount; - if (amount.abs().compareTo(new UFDouble(0.005)) < 0){ + if (amount == null) { + return UFDouble.ZERO_DBL; + } + amount = (amount.compareTo(UFDouble.ZERO_DBL) < 0) ? UFDouble.ZERO_DBL : amount; + if (amount.abs().compareTo(new UFDouble(0.005)) < 0) { amount = UFDouble.ZERO_DBL; } return amount; @@ -1675,11 +1691,12 @@ public class InvoiceTransferUtil { /** * 把UFDate转换成yyyy-MM-dd格式 + * * @param ufDate * @return */ - public static String getFormatDate(UFDate ufDate){ - if(ufDate==null){ + public static String getFormatDate(UFDate ufDate) { + if (ufDate == null) { return null; } Date date = ufDate.toDate();