Преглед на файлове

fix: 开票修改,待完善

luofeiyun преди 17 часа
родител
ревизия
db76ff0b4b

+ 38 - 41
ship-module-trade/ship-module-trade-biz/src/main/java/com/yc/ship/module/trade/service/invoice/impl/InvoiceGroupServiceImpl.java

@@ -876,13 +876,13 @@ public class InvoiceGroupServiceImpl implements InvoiceGroupService {
             JSONArray detailArray = new JSONArray();
             List<InvoiceInventoryDO> inventoryList = invoiceInventoryService.getInvoiceInventoryListByInvoiceId(invoice.getId());
             JSONObject detailObj;
-            BigDecimal taxExcludedAmount = BigDecimal.ZERO;
-            BigDecimal taxExcludedAmounttotal = BigDecimal.ZERO;
-            BigDecimal se = BigDecimal.ZERO;
-            BigDecimal tse = BigDecimal.ZERO;
-            BigDecimal tje = BigDecimal.ZERO;
-            BigDecimal taxIncludedAmount = BigDecimal.ZERO;
-            BigDecimal taxIncludedAmounttotal = BigDecimal.ZERO;
+            // 税价合计总金额
+            List<BigDecimal> zsjhjList = new ArrayList<>();
+            // 总税额
+            List<BigDecimal> zseList = new ArrayList<>();
+            // 总不含税金额
+            List<BigDecimal> zbhsjeList = new ArrayList<>();
+
             if (inventoryList.isEmpty()) {
                 int index = 1;
                 detailObj = new JSONObject();
@@ -898,22 +898,18 @@ public class InvoiceGroupServiceImpl implements InvoiceGroupService {
                 BigDecimal taxRate = new BigDecimal(configApi.getPlatformConfigValueByKey("newinvoice.taxRate"));
                 detailObj.set("SL", taxRate);
                 //含税金额
-                taxIncludedAmount = invoice.getPrice().add(invoice.getZkprice());
-                taxIncludedAmounttotal = invoice.getPrice();
+                BigDecimal hsje = invoice.getPrice().add(invoice.getZkprice()).setScale(2, RoundingMode.HALF_UP);
                 if (type == 1) {
-                    taxIncludedAmount = BigDecimal.ZERO.subtract(invoice.getPrice());
+                    hsje = BigDecimal.ZERO.subtract(invoice.getPrice()).setScale(2, RoundingMode.HALF_UP);
                 }
-//                String dylzfpmxxh = String.valueOf(IdWorker.getId()).substring(0,8);
-//                detailObj.set("DYLZFPMXXH", dylzfpmxxh);
+                zsjhjList.add(hsje);
                 //不含税金额
-                taxExcludedAmount = taxIncludedAmount.divide(new BigDecimal(1).add(taxRate), 2, RoundingMode.HALF_UP);
-                taxExcludedAmounttotal = taxIncludedAmounttotal.divide(new BigDecimal(1).add(taxRate), 2, RoundingMode.HALF_UP);
-                //金额
-                tje = taxIncludedAmount.setScale(2, RoundingMode.HALF_UP);
-                detailObj.set("JE", taxIncludedAmount.setScale(2, RoundingMode.HALF_UP));
+                BigDecimal bhsje = hsje.subtract(hsje.multiply(taxRate)).setScale(2, RoundingMode.HALF_UP);
+                zbhsjeList.add(bhsje);
+                detailObj.set("JE", hsje);
                 //税额
-                se = taxIncludedAmount.subtract(taxExcludedAmount).setScale(2, RoundingMode.HALF_UP);
-                tse =se;
+                BigDecimal se = hsje.subtract(bhsje).setScale(2, RoundingMode.HALF_UP);
+                zseList.add(se);
                 detailObj.set("SE", se);
                 //扣除额
                 detailObj.set("KCE", "");
@@ -938,18 +934,17 @@ public class InvoiceGroupServiceImpl implements InvoiceGroupService {
                     //税率
                     detailObj2.set("SL", taxRate);
                     //含税金额
-                    taxIncludedAmount = BigDecimal.ZERO.subtract( invoice.getZkprice());
-//                String dylzfpmxxh = String.valueOf(IdWorker.getId()).substring(0,8);
-//                detailObj.set("DYLZFPMXXH", dylzfpmxxh);
+                    BigDecimal hsje1 = BigDecimal.ZERO.subtract(invoice.getZkprice()).setScale(2, RoundingMode.HALF_UP);
+                    zsjhjList.add(hsje1);
                     //不含税金额
-                    taxExcludedAmount = taxIncludedAmount.divide(new BigDecimal(1).add(taxRate), 2, RoundingMode.HALF_UP);
+                    BigDecimal bhsje1 = hsje1.subtract(hsje1.multiply(taxRate)).setScale(2, RoundingMode.HALF_UP);
+                    zbhsjeList.add(bhsje1);
                     //金额
-                    tje = tje.add(taxIncludedAmount.setScale(2, RoundingMode.HALF_UP));
-                    detailObj2.set("JE", taxIncludedAmount.setScale(2, RoundingMode.HALF_UP));
+                    detailObj2.set("JE", hsje1);
                     //税额
-                    se = taxIncludedAmount.subtract(taxExcludedAmount);
-                    tse = tse.add(se.setScale(2, RoundingMode.HALF_UP));
-                    detailObj2.set("SE", se.setScale(2, RoundingMode.HALF_UP));
+                    BigDecimal se1 = hsje1.subtract(bhsje1).setScale(2, RoundingMode.HALF_UP);
+                    zseList.add(se1);
+                    detailObj2.set("SE", se1);
                     //扣除额
                     detailObj2.set("KCE", "");
                     //行性质。0-正常行 1-折扣行 2-被折扣行
@@ -966,15 +961,18 @@ public class InvoiceGroupServiceImpl implements InvoiceGroupService {
                 InvoiceInventorySaveReqVO saveReqVO = new InvoiceInventorySaveReqVO();
                 saveReqVO.setInvoiceId(invoice.getId());
                 saveReqVO.setSort(index);
-                saveReqVO.setAmount(taxIncludedAmount);
-                saveReqVO.setTax(se);
+                // 总含税金额
+                BigDecimal totalHsje = zsjhjList.stream().reduce(BigDecimal.ZERO, BigDecimal::add);
+                saveReqVO.setAmount(totalHsje);
+                // 总税额
+                BigDecimal totalSe = zseList.stream().reduce(BigDecimal.ZERO, BigDecimal::add);
+                saveReqVO.setTax(totalSe);
                 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);
@@ -1012,22 +1010,21 @@ public class InvoiceGroupServiceImpl implements InvoiceGroupService {
                     //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", tje);
+            // 总不含税金额
+            BigDecimal totalBhsje = zbhsjeList.stream().reduce(BigDecimal.ZERO, BigDecimal::add);
+            reqObj.set("HJJE", totalBhsje);
             //合计税额
-            reqObj.set("HJSE", tse);
+            BigDecimal totalSe = zseList.stream().reduce(BigDecimal.ZERO, BigDecimal::add);
+            reqObj.set("HJSE", totalSe);
             if (StringUtils.isNotBlank(remark)) {
                 //备注
                 reqObj.set("BZ", remark);
             }
             //价税合计
-            reqObj.set("JSHJ", taxIncludedAmounttotal.setScale(2, RoundingMode.HALF_UP));
+            BigDecimal totalSjhj = zsjhjList.stream().reduce(BigDecimal.ZERO, BigDecimal::add);
+            reqObj.set("JSHJ", totalSjhj);
             //系统来源
             reqObj.set("SX_XTLY", StrUtil.isNotBlank(sysSource) ? sysSource : "SX_LYEQ");
 //            reqObj.set("DDMXXX", detailArray);
@@ -1037,8 +1034,8 @@ public class InvoiceGroupServiceImpl implements InvoiceGroupService {
             reqDDZ.add(jsonObject);
             log.error("请求参数:{}", reqDDZ);
 
-            invoice.setCHjse(se);
-            invoice.setCBhsje(taxExcludedAmounttotal);
+            invoice.setCHjse(totalSe);
+            invoice.setCBhsje(totalBhsje);
         });
         requestBody.set("DDZXX", reqDDZ);
         return requestBody;