|
|
@@ -597,6 +597,209 @@ public class InvoiceGroupServiceImpl implements InvoiceGroupService {
|
|
|
String salesName = configApi.getPlatformConfigValueByKey("newinvoice.sales.name");
|
|
|
String batchNo = IdUtil.fastSimpleUUID();
|
|
|
|
|
|
+ JSONObject requestBody = new JSONObject();
|
|
|
+ JSONArray reqDDZ = new JSONArray();
|
|
|
+ JSONObject reqDDPC = new JSONObject();
|
|
|
+ //订单请求批次号
|
|
|
+ reqDDPC.set("DDQQPCH", batchNo);
|
|
|
+ //纳税人识别号
|
|
|
+ reqDDPC.set("NSRSBH", taxNum);
|
|
|
+ //发票种类代码01-专用发票 02-普通发票
|
|
|
+ if (invoiceList.get(0).getInvoiceType() == null) {
|
|
|
+ reqDDPC.set("FPLXDM", "002");
|
|
|
+ } else {
|
|
|
+ reqDDPC.set("FPLXDM", DigitalInvoiceTypeEnum.valueOf(invoiceList.get(0).getInvoiceType()).getCode());
|
|
|
+ }
|
|
|
+ requestBody.set("DDPCXX", reqDDPC);
|
|
|
+ invoiceList.forEach(invoice -> {
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ JSONObject reqObj = new JSONObject();
|
|
|
+ //订单请求流水号
|
|
|
+ reqObj.set("DDQQLSH", invoice.getFpqqlsh());
|
|
|
+ //开票类型(0蓝字发票 1红字发票)
|
|
|
+ reqObj.set("KPLX", type);
|
|
|
+ //销货方纳税人识别号
|
|
|
+ reqObj.set("XHFSBH", taxNum);
|
|
|
+ //销货方名称
|
|
|
+ reqObj.set("XHFMC", salesName);
|
|
|
+ //销货方地址
|
|
|
+ reqObj.set("XHFDZ", "");
|
|
|
+ //销货方电话
|
|
|
+ reqObj.set("XHFDH", "");
|
|
|
+ //销货方银行名称
|
|
|
+ reqObj.set("XHFYH", configApi.getPlatformConfigValueByKey("newinvoice.sales.bank"));
|
|
|
+ //销货方银行账号
|
|
|
+ reqObj.set("XHFZH", configApi.getPlatformConfigValueByKey("newinvoice.sales.bankaccount"));
|
|
|
+
|
|
|
+ reqObj.set("DDH", invoice.getTransactionNo());
|
|
|
+
|
|
|
+ //开票员,以电子税局绑定人员为准
|
|
|
+ reqObj.set("KPR", invoice.getBuyerClerk());
|
|
|
+
|
|
|
+ //购买方编码
|
|
|
+ reqObj.set("GMFYH", "");
|
|
|
+ //购买方纳税人识别号
|
|
|
+ reqObj.set("GMFSBH", invoice.getBuyerTaxCode());
|
|
|
+ //购买方名称(当GMFBM为空并且开票方式为自动开票时必填。如果FPLXDM为002,且GMFLX为03(个人)时,GMFMC必须以(个人)字样结尾”(”为全角)
|
|
|
+ reqObj.set("GMFMC", invoice.getBuyerName());
|
|
|
+ //购买方地址
|
|
|
+ reqObj.set("GMFDZ", invoice.getBuyerAddress());
|
|
|
+ //购买方电话
|
|
|
+ reqObj.set("GMFDH", invoice.getBuyerPhone());
|
|
|
+ //购买方银行名称
|
|
|
+ reqObj.set("GMFYH", invoice.getBuyerBank());
|
|
|
+ //购买方电话
|
|
|
+ reqObj.set("GMFZH", invoice.getBuyerAccount());
|
|
|
+ //购买方类型(01企业,02机关事业单位,03个人,04其他,如不填写,默认为04)
|
|
|
+ if (invoice.getTitleType() != null) {
|
|
|
+ if (invoice.getTitleType() == 0) {
|
|
|
+ //购买方名称(当GMFBM为空并且开票方式为自动开票时必填。如果FPLXDM为002,且GMFLX为03(个人)时,GMFMC必须以(个人)字样结尾”(”为全角)
|
|
|
+ reqObj.set("GMFMC", invoice.getBuyerName() + "(个人)");
|
|
|
+ reqObj.set("GMFLX", "03");
|
|
|
+ } else if (invoice.getTitleType() == 1) {
|
|
|
+ reqObj.set("GMFLX", "01");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ reqObj.set("GMFLX", "04");
|
|
|
+ }
|
|
|
+// reqObj.set("GMFLX", invoice.getTitleType());
|
|
|
+ //购货方手机
|
|
|
+ reqObj.set("GMFSJH", invoice.getBuyerTel());
|
|
|
+ //购方邮箱,如果填写,发票类别为电子发票时会自动发送邮件
|
|
|
+ reqObj.set("GMFDZYX", invoice.getBuyerEmail());
|
|
|
+
|
|
|
+ JSONArray detailArray = new JSONArray();
|
|
|
+ List<InvoiceInventoryDO> inventoryList = invoiceInventoryService.getInvoiceInventoryListByInvoiceId(invoice.getId());
|
|
|
+ JSONObject detailObj;
|
|
|
+ BigDecimal taxExcludedAmount = BigDecimal.ZERO;
|
|
|
+ BigDecimal se = BigDecimal.ZERO;
|
|
|
+ BigDecimal taxIncludedAmount = BigDecimal.ZERO;
|
|
|
+ if (inventoryList.isEmpty()) {
|
|
|
+ int index = 1;
|
|
|
+ detailObj = new JSONObject();
|
|
|
+ detailObj.set("XH", index);
|
|
|
+ String GoodsCode = configApi.getPlatformConfigValueByKey("newinvoice.goods.code");
|
|
|
+ String spbm = StrUtil.padAfter(GoodsCode, 19, "0");
|
|
|
+ //商品编码
|
|
|
+ detailObj.set("SPBM", spbm);
|
|
|
+ String spmc = configApi.getPlatformConfigValueByKey("newinvoice.goods.simpleCode");
|
|
|
+ //项目名称
|
|
|
+ detailObj.set("XMMC", spmc);
|
|
|
+ //税率
|
|
|
+ BigDecimal taxRate = new BigDecimal(configApi.getPlatformConfigValueByKey("newinvoice.taxRate"));
|
|
|
+ detailObj.set("SL", taxRate);
|
|
|
+ //含税金额
|
|
|
+ taxIncludedAmount = invoice.getPrice();
|
|
|
+ if (type == 1) {
|
|
|
+ taxIncludedAmount = BigDecimal.ZERO.subtract(invoice.getPrice());
|
|
|
+ }
|
|
|
+// String dylzfpmxxh = String.valueOf(IdWorker.getId()).substring(0,8);
|
|
|
+// detailObj.set("DYLZFPMXXH", dylzfpmxxh);
|
|
|
+ //不含税金额
|
|
|
+ taxExcludedAmount = taxIncludedAmount.divide(new BigDecimal(1).add(taxRate), 2, RoundingMode.HALF_UP);
|
|
|
+ //金额
|
|
|
+ detailObj.set("JE", taxIncludedAmount.setScale(2, RoundingMode.HALF_UP));
|
|
|
+ //税额
|
|
|
+ se = taxIncludedAmount.subtract(taxExcludedAmount);
|
|
|
+ detailObj.set("SE", se.setScale(2, RoundingMode.HALF_UP));
|
|
|
+ //扣除额
|
|
|
+ detailObj.set("KCE", "");
|
|
|
+ //行性质。0-正常行 1-折扣行 2-被折扣行
|
|
|
+ detailObj.set("FPHXZ", "0");
|
|
|
+ //含税标志
|
|
|
+ detailObj.set("HSBZ", "1");
|
|
|
+ //空:非零税率,1:免税,2:不征税 3:普通零税率
|
|
|
+ detailObj.set("LSLBS", "");
|
|
|
+ //0:不使用,1:使用,SPID为空时必填
|
|
|
+ detailObj.set("YHZCBS", 0);
|
|
|
+ detailArray.add(detailObj);
|
|
|
+
|
|
|
+ InvoiceInventorySaveReqVO saveReqVO = new InvoiceInventorySaveReqVO();
|
|
|
+ saveReqVO.setInvoiceId(invoice.getId());
|
|
|
+ saveReqVO.setSort(index);
|
|
|
+ saveReqVO.setAmount(taxIncludedAmount);
|
|
|
+ saveReqVO.setTax(se);
|
|
|
+ saveReqVO.setCode(spbm);
|
|
|
+ saveReqVO.setName(spmc);
|
|
|
+ saveReqVO.setTaxRate(taxRate);
|
|
|
+ saveReqVO.setFphxz(0);
|
|
|
+ saveReqVO.setHsbz(1);
|
|
|
+ saveReqVO.setYhzcbs(0);
|
|
|
+// saveReqVO.setDylzfpmxxh(dylzfpmxxh);
|
|
|
+ InvoiceInventoryDO invoiceInventoryDO = invoiceInventoryService.createInvoiceInventory(saveReqVO);
|
|
|
+ inventoryList = new ArrayList<>(3);
|
|
|
+ inventoryList.add(invoiceInventoryDO);
|
|
|
+ } else {
|
|
|
+ for (InvoiceInventoryDO invoiceInventoryDO : inventoryList) {
|
|
|
+ detailObj = new JSONObject();
|
|
|
+ detailObj.set("XH", invoiceInventoryDO.getSort());
|
|
|
+ //商品编码
|
|
|
+ detailObj.set("SPBM", invoiceInventoryDO.getCode());
|
|
|
+ //项目名称
|
|
|
+ detailObj.set("XMMC", invoiceInventoryDO.getName());
|
|
|
+ //税率
|
|
|
+ detailObj.set("SL", invoiceInventoryDO.getTaxRate());
|
|
|
+ //含税金额
|
|
|
+ BigDecimal thisTaxIncludedAmount = invoiceInventoryDO.getAmount();
|
|
|
+ if (type == 1) {
|
|
|
+ detailObj.set("DYLZFPMXXH", invoiceInventoryDO.getDylzfpmxxh());
|
|
|
+ thisTaxIncludedAmount = BigDecimal.ZERO.subtract(invoiceInventoryDO.getAmount());
|
|
|
+ }
|
|
|
+ //金额
|
|
|
+ detailObj.set("JE", thisTaxIncludedAmount.setScale(2, RoundingMode.HALF_UP));
|
|
|
+ //不含税金额
|
|
|
+ BigDecimal thisTaxExcludedAmount = thisTaxIncludedAmount.divide(new BigDecimal(1).add(invoiceInventoryDO.getTaxRate()), 2, RoundingMode.HALF_UP);
|
|
|
+ //税额
|
|
|
+ BigDecimal thisSe = thisTaxIncludedAmount.subtract(thisTaxExcludedAmount);
|
|
|
+ detailObj.set("SE", thisSe.setScale(2, RoundingMode.HALF_UP));
|
|
|
+ //扣除额
|
|
|
+ detailObj.set("KCE", invoiceInventoryDO.getDeductionAmount() == null ? "" : invoiceInventoryDO.getDeductionAmount());
|
|
|
+ //行性质。0-正常行 1-折扣行 2-被折扣行
|
|
|
+ detailObj.set("FPHXZ", invoiceInventoryDO.getFphxz());
|
|
|
+ //含税标志
|
|
|
+ detailObj.set("HSBZ", invoiceInventoryDO.getHsbz());
|
|
|
+ //空:非零税率,1:免税,2:不征税 3:普通零税率
|
|
|
+ detailObj.set("LSLBS", invoiceInventoryDO.getLslbs() == null ? "" : invoiceInventoryDO.getLslbs());
|
|
|
+ //0:不使用,1:使用,SPID为空时必填
|
|
|
+ detailObj.set("YHZCBS", invoiceInventoryDO.getYhzcbs());
|
|
|
+ detailArray.add(detailObj);
|
|
|
+
|
|
|
+ taxExcludedAmount = taxExcludedAmount.add(thisTaxExcludedAmount);
|
|
|
+ se = se.add(thisSe);
|
|
|
+ taxIncludedAmount = taxIncludedAmount.add(thisTaxIncludedAmount);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //合计金额
|
|
|
+ reqObj.set("HJJE", taxExcludedAmount.setScale(2, RoundingMode.HALF_UP));
|
|
|
+ //合计税额
|
|
|
+ reqObj.set("HJSE", se.setScale(2, RoundingMode.HALF_UP));
|
|
|
+ if (StringUtils.isNotBlank(remark)) {
|
|
|
+ //备注
|
|
|
+ reqObj.set("BZ", remark);
|
|
|
+ }
|
|
|
+ //价税合计
|
|
|
+ reqObj.set("JSHJ", taxIncludedAmount.setScale(2, RoundingMode.HALF_UP));
|
|
|
+ //系统来源
|
|
|
+ reqObj.set("SX_XTLY", StrUtil.isNotBlank(sysSource) ? sysSource : "SX_LYEQ");
|
|
|
+// reqObj.set("DDMXXX", detailArray);
|
|
|
+ jsonObject.set("DDTXX", reqObj);
|
|
|
+ jsonObject.set("DDMXXX", detailArray);
|
|
|
+// reqDDZ.add(reqObj);
|
|
|
+ reqDDZ.add(jsonObject);
|
|
|
+ invoice.setCHjse(se);
|
|
|
+ invoice.setCBhsje(taxExcludedAmount);
|
|
|
+ });
|
|
|
+ requestBody.set("DDZXX", reqDDZ);
|
|
|
+ return requestBody;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private JSONObject buildRequestParamNew(List<InvoiceDO> invoiceList, Integer type, String sysSource, String remark) {
|
|
|
+ String taxNum = configApi.getPlatformConfigValueByKey("newinvoice.group.tax");
|
|
|
+ String salesName = configApi.getPlatformConfigValueByKey("newinvoice.sales.name");
|
|
|
+ String batchNo = IdUtil.fastSimpleUUID();
|
|
|
+
|
|
|
JSONObject requestBody = new JSONObject();
|
|
|
JSONArray reqDDZ = new JSONArray();
|
|
|
JSONObject reqDDPC = new JSONObject();
|