浏览代码

电子发票业务流程优化

lishiqiang 2 周之前
父节点
当前提交
fe31d7db96

+ 5 - 2
ship-module-trade/ship-module-trade-api/src/main/java/com/yc/ship/module/trade/api/invoice/dto/InvoicingReqDTO.java

@@ -39,12 +39,15 @@ public class InvoicingReqDTO {
     private String buyerEmail;
 
     /** 开票金额 */
-    @Schema(description = "开票金额",example="")
+    @Schema(description = "开票金额(总金额)",example="")
     private BigDecimal totalPrice;
 
-    @Schema(description = "当前开票金额",example="")
+    @Schema(description = "当前开票金额(实际金额)",example="")
     private BigDecimal price;
 
+    @Schema(description = "当前开票折扣金额",example="")
+    private BigDecimal zkprice;
+
     /** 买方地址 */
     @Schema(description = "买方地址",example="")
     private String buyerAddress;

+ 5 - 0
ship-module-trade/ship-module-trade-biz/src/main/java/com/yc/ship/module/trade/dal/dataobject/invoice/InvoiceDO.java

@@ -118,6 +118,11 @@ public class InvoiceDO extends TenantBaseDO {
      * 开票金额
      */
     private BigDecimal price;
+
+    /**
+     * 折扣金额
+     */
+    private BigDecimal zkprice;
     /**
      * 发票请求流水号
      */

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

@@ -672,8 +672,10 @@ public class InvoiceGroupServiceImpl implements InvoiceGroupService {
             List<InvoiceInventoryDO> inventoryList = invoiceInventoryService.getInvoiceInventoryListByInvoiceId(invoice.getId());
             JSONObject detailObj;
             BigDecimal taxExcludedAmount = BigDecimal.ZERO;
+            BigDecimal taxExcludedAmounttotal = BigDecimal.ZERO;
             BigDecimal se = BigDecimal.ZERO;
             BigDecimal taxIncludedAmount = BigDecimal.ZERO;
+            BigDecimal taxIncludedAmounttotal = BigDecimal.ZERO;
             if (inventoryList.isEmpty()) {
                 int index = 1;
                 detailObj = new JSONObject();
@@ -689,7 +691,8 @@ public class InvoiceGroupServiceImpl implements InvoiceGroupService {
                 BigDecimal taxRate = new BigDecimal(configApi.getPlatformConfigValueByKey("newinvoice.taxRate"));
                 detailObj.set("SL", taxRate);
                 //含税金额
-                taxIncludedAmount = invoice.getPrice();
+                taxIncludedAmount = invoice.getPrice().add(invoice.getZkprice());
+                taxIncludedAmounttotal = invoice.getPrice();
                 if (type == 1) {
                     taxIncludedAmount = BigDecimal.ZERO.subtract(invoice.getPrice());
                 }
@@ -697,6 +700,7 @@ public class InvoiceGroupServiceImpl implements InvoiceGroupService {
 //                detailObj.set("DYLZFPMXXH", dylzfpmxxh);
                 //不含税金额
                 taxExcludedAmount = taxIncludedAmount.divide(new BigDecimal(1).add(taxRate), 2, RoundingMode.HALF_UP);
+                taxExcludedAmounttotal = taxIncludedAmounttotal.divide(new BigDecimal(1).add(taxRate), 2, RoundingMode.HALF_UP);
                 //金额
                 detailObj.set("JE", taxIncludedAmount.setScale(2, RoundingMode.HALF_UP));
                 //税额
@@ -713,6 +717,41 @@ public class InvoiceGroupServiceImpl implements InvoiceGroupService {
                 //0:不使用,1:使用,SPID为空时必填
                 detailObj.set("YHZCBS", 0);
                 detailArray.add(detailObj);
+
+
+                if(invoice.getZkprice() != null && invoice.getZkprice().compareTo(BigDecimal.ZERO) > 0) {
+                    JSONObject detailObj2 = new JSONObject();
+                    detailObj2.set("XH", index);
+                    //商品编码
+                    detailObj2.set("SPBM", spbm);
+                    //项目名称
+                    detailObj2.set("XMMC", spmc);
+                    //税率
+                    detailObj2.set("SL", taxRate);
+                    //含税金额
+                    taxIncludedAmount = BigDecimal.ZERO.subtract( invoice.getZkprice());
+//                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);
+                    //金额
+                    detailObj2.set("JE", taxIncludedAmount.setScale(2, RoundingMode.HALF_UP));
+                    //税额
+                    se = taxIncludedAmount.subtract(taxExcludedAmount);
+                    detailObj2.set("SE", se.setScale(2, RoundingMode.HALF_UP));
+                    //扣除额
+                    detailObj2.set("KCE", "");
+                    //行性质。0-正常行 1-折扣行 2-被折扣行
+                    detailObj2.set("FPHXZ", "0");
+                    //含税标志
+                    detailObj2.set("HSBZ", "1");
+                    //空:非零税率,1:免税,2:不征税 3:普通零税率
+                    detailObj2.set("LSLBS", "");
+                    //0:不使用,1:使用,SPID为空时必填
+                    detailObj2.set("YHZCBS", 0);
+                    detailArray.add(detailObj2);
+                }
+
                 InvoiceInventorySaveReqVO saveReqVO = new InvoiceInventorySaveReqVO();
                 saveReqVO.setInvoiceId(invoice.getId());
                 saveReqVO.setSort(index);
@@ -777,7 +816,7 @@ public class InvoiceGroupServiceImpl implements InvoiceGroupService {
                 reqObj.set("BZ", remark);
             }
             //价税合计
-            reqObj.set("JSHJ", taxIncludedAmount.setScale(2, RoundingMode.HALF_UP));
+            reqObj.set("JSHJ", taxIncludedAmounttotal.setScale(2, RoundingMode.HALF_UP));
             //系统来源
             reqObj.set("SX_XTLY", StrUtil.isNotBlank(sysSource) ? sysSource : "SX_LYEQ");
 //            reqObj.set("DDMXXX", detailArray);
@@ -786,7 +825,7 @@ public class InvoiceGroupServiceImpl implements InvoiceGroupService {
 //            reqDDZ.add(reqObj);
             reqDDZ.add(jsonObject);
             invoice.setCHjse(se);
-            invoice.setCBhsje(taxExcludedAmount);
+            invoice.setCBhsje(taxExcludedAmounttotal);
         });
         requestBody.set("DDZXX", reqDDZ);
         return requestBody;

+ 5 - 0
ship-module-trade/ship-module-trade-biz/src/main/java/com/yc/ship/module/trade/service/invoice/impl/InvoiceServiceImpl.java

@@ -96,6 +96,7 @@ public class InvoiceServiceImpl implements InvoiceService {
                 throw exception0(500, "订单开票失败,开票金额不能为"+reqDTO.getTotalPrice());
             }
         }
+        BigDecimal zk = BigDecimal.ZERO;
         //查询订单及金额
         for (String orderNo : reqDTO.getOrderIdList()) {
             TradeOrderDO order = tradeOrderRepositoryService.getOrderByNo(orderNo);
@@ -106,9 +107,11 @@ public class InvoiceServiceImpl implements InvoiceService {
             if (order.getIsInvoice() != null && ObjectUtil.equals(order.getIsInvoice(), InvoiceStatusEnum.INVOICE_SUCCESS.getValue())) {
                 throw exception0(500, "订单{}已开票", orderNo);
             }
+
             Asserts.isTrue(ObjectUtil.equals(order.getIsInvoice(), InvoiceStatusEnum.NOT_INVOICED.getValue())
                     || ObjectUtil.equals(order.getIsInvoice(), InvoiceStatusEnum.INVOICE_FAILED.getValue()), ORDER_INVOICED.getCode(), "订单{}已开票", orderNo);
             amt = amt.add(order.getPayAmount());
+            zk=zk.add(order.getAmount().multiply(order.getPayAmount()));
             //减去退款金额
             BigDecimal orderRefundAmount = tradeRefundRepositoryService.getOrderRefundAmount(order.getId());
             if (orderRefundAmount != null) {
@@ -127,6 +130,7 @@ public class InvoiceServiceImpl implements InvoiceService {
         if (reqDTO.getTotalPrice() == null) {
             reqDTO.setTotalPrice(reqDTO.getPrice());
         }
+        reqDTO.setZkprice(zk);
         //计算开票金额,如果未传值则用订单总金额
         if (reqDTO.getPrice() == null) {
             reqDTO.setPrice(amt);
@@ -241,6 +245,7 @@ public class InvoiceServiceImpl implements InvoiceService {
         invoiceDO.setTransactionNo(tradeUUCodeUtils.generateOrderNo(INVOICE_PREFIX));
         invoiceDO.setSalesTaxCode(taxCode);
         invoiceDO.setFpqqlsh(serialNum);
+        invoiceDO.setZkprice(reqDTO.getZkprice());
         invoiceDO.setSalesName(configApi.getPlatformConfigValueByKey("invoice.sales.name"));
         invoiceDO.setSalesAddress(configApi.getPlatformConfigValueByKey("invoice.sales.addr"));
         invoiceDO.setDeleted(false);

+ 1 - 1
ship-module-trade/ship-module-trade-biz/src/main/java/com/yc/ship/module/trade/service/smsSendconfig/MessageSendServiceImpl.java

@@ -87,7 +87,7 @@ public class MessageSendServiceImpl implements MessageSendService {
                 map.put("routeName", smsSendconfigQueryRespVO.getRouteName());
                 map.put("boatName", smsSendconfigQueryRespVO.getShipName());
                 map.put("startTime", smsSendconfigQueryRespVO.getStartTime());
-                Date lastDate = DateUtil.offsetDay(DateUtil.parse(smsSendconfigQueryRespVO.getStartTime()), -7);
+                Date lastDate = DateUtil.offsetDay(DateUtil.parse(smsSendconfigQueryRespVO.getStartTime()), -4);
                 map.put("lastTime", DateUtil.format(lastDate, "yyyy-MM-dd"));
                 NotifySendSingleToUserReqDTO reqDTO = new NotifySendSingleToUserReqDTO();
                 reqDTO.setTemplateParams(map);