浏览代码

售后管理

yzc 1 年之前
父节点
当前提交
fea9d7b943

+ 8 - 9
hx-account/src/main/java/com/fjhx/account/entity/account/enums/PaymentTypeEnum.java

@@ -7,17 +7,16 @@ import java.util.Map;
 
 //打款类型
 public enum PaymentTypeEnum {
-    UNDER_REVIEW("10", "请款"),
-    REJECT("20", "采购付款"),
-    RECEIVE("30", "退货到款登记"),
+    UNDER_REVIEW(10, "请款"),
+    REJECT(20, "采购付款"),
+    RECEIVE(30, "退货到款登记"),
     ;
-    private String key;
+    private static Map<Integer, String> map = new LinkedHashMap<>();
 
     private String value;
+    private Integer key;
 
-    private static Map<String, String> map = new LinkedHashMap<>();
-
-    PaymentTypeEnum(String key, String value) {
+    PaymentTypeEnum(Integer key, String value) {
         this.key = key;
         this.value = value;
     }
@@ -27,7 +26,7 @@ public enum PaymentTypeEnum {
      *
      * @return
      */
-    public static Map<String, String> getMap() {
+    public static Map<Integer, String> getMap() {
         if (MapUtils.isNotEmpty(map)) {
             return map;
         }
@@ -37,7 +36,7 @@ public enum PaymentTypeEnum {
         return map;
     }
 
-    public String getKey() {
+    public Integer getKey() {
         return key;
     }
 

+ 1 - 1
hx-account/src/main/java/com/fjhx/account/entity/account/po/AccountPayment.java

@@ -69,7 +69,7 @@ public class AccountPayment extends BasePo {
     /**
      * 付款类型(10:请款  20 采购付款) 字典payment_type
      */
-    private String type;
+    private Integer type;
 
     /**
      * 摘要

+ 1 - 1
hx-account/src/main/java/com/fjhx/account/entity/account/po/AccountRequestFunds.java

@@ -55,7 +55,7 @@ public class AccountRequestFunds extends BasePo {
     /**
      * 请款类型(字典funds_type)
      */
-    private String type;
+    private Integer type;
 
     /**
      * 请款总额

+ 4 - 7
hx-account/src/main/java/com/fjhx/account/service/account/impl/AccountRequestFundsServiceImpl.java

@@ -27,7 +27,6 @@ import com.fjhx.flow.entity.flow.po.FlowExample;
 import com.fjhx.flow.service.flow.FlowExampleService;
 import com.ruoyi.common.core.domain.BasePo;
 import com.ruoyi.common.core.domain.entity.SysDept;
-import com.ruoyi.common.exception.ServiceException;
 import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.common.utils.wrapper.IWrapper;
 import com.ruoyi.common.utils.wrapper.SqlField;
@@ -195,20 +194,18 @@ public class AccountRequestFundsServiceImpl extends ServiceImpl<AccountRequestFu
 
         // 查询归属公司的名称
         Corporation corporation = corporationService.getById(accountRequestFundsVo.getCorporationId());
-        if (ObjectUtil.isEmpty(corporation)) {
-            throw new ServiceException("没有找到归属公司信息");
+        if (ObjectUtil.isNotEmpty(corporation)) {
+            accountRequestFundsVo.setCorporationName(corporation.getName());
         }
-        accountRequestFundsVo.setCorporationName(corporation.getName());
 
         // 切换数据源
         DynamicDataSourceContextHolder.push(SourceConstant.BASE);
 
         // 查询部门名称信息
         SysDept sysDept = sysDeptService.getById(accountRequestFundsVo.getDepartmentId());
-        if (ObjectUtil.isEmpty(sysDept)) {
-            throw new ServiceException("没有找到归属部门信息");
+        if (ObjectUtil.isNotEmpty(sysDept)) {
+            accountRequestFundsVo.setDeptName(sysDept.getDeptName());
         }
-        accountRequestFundsVo.setDeptName(sysDept.getDeptName());
 
         // 赋值流程实例id
         FlowExample flowExample = flowExampleService.getOne(q -> q.eq(FlowExample::getBusinessId, accountRequestFunds.getId()));

+ 19 - 1
hx-sale/src/main/java/com/fjhx/sale/entity/after/po/AfterSales.java

@@ -5,6 +5,8 @@ import com.ruoyi.common.core.domain.BasePo;
 import lombok.Getter;
 import lombok.Setter;
 
+import java.math.BigDecimal;
+
 /**
  * <p>
  * sale_售后管理
@@ -71,8 +73,24 @@ public class AfterSales extends BasePo {
     /**
      * 售后数量
      */
-    private Long quantity;
+    private BigDecimal quantity;
 
     private Long companyId;
 
+    private Long flowId;
+
+    /**
+     * 开户银行
+     */
+    private String openingBank;
+    /**
+     * 账户名称
+     */
+    private String accountName;
+    /**
+     * 开户账号
+     */
+    private String accountOpening;
+
+
 }

+ 136 - 0
hx-sale/src/main/java/com/fjhx/sale/flow/AfterSalesFlow.java

@@ -0,0 +1,136 @@
+package com.fjhx.sale.flow;
+
+import cn.hutool.core.util.ObjectUtil;
+import com.alibaba.fastjson.JSONObject;
+import com.fjhx.account.entity.account.enums.PaymentStatusEnum;
+import com.fjhx.account.entity.account.po.AccountPayment;
+import com.fjhx.account.service.account.AccountPaymentService;
+import com.fjhx.common.enums.CodingRuleEnum;
+import com.fjhx.common.enums.FlowStatusEnum1;
+import com.fjhx.common.service.coding.CodingRuleService;
+import com.fjhx.common.utils.Assert;
+import com.fjhx.flow.core.FlowDelegate;
+import com.fjhx.sale.entity.after.dto.AfterSalesDto;
+import com.fjhx.sale.entity.after.po.AfterSales;
+import com.fjhx.sale.entity.contract.po.Contract;
+import com.fjhx.sale.entity.contract.po.ContractProduct;
+import com.fjhx.sale.service.after.AfterSalesService;
+import com.fjhx.sale.service.contract.ContractProductService;
+import com.fjhx.sale.service.contract.ContractService;
+import com.ruoyi.common.core.domain.entity.SysUser;
+import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.system.service.ISysUserService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.math.BigDecimal;
+import java.util.Date;
+
+@Component
+public class AfterSalesFlow extends FlowDelegate {
+
+    private final AfterSalesService afterSalesService;
+    private final CodingRuleService codingRuleService;
+    private final ContractProductService contractProductService;
+    private final ISysUserService userService;
+    private final AccountPaymentService accountPaymentService;
+    private final ContractService contractService;
+
+    @Autowired
+    public AfterSalesFlow(AfterSalesService afterSalesService, CodingRuleService codingRuleService, ContractProductService contractProductService, ISysUserService userService, AccountPaymentService accountPaymentService, ContractService contractService) {
+        this.afterSalesService = afterSalesService;
+        this.codingRuleService = codingRuleService;
+        this.contractProductService = contractProductService;
+        this.userService = userService;
+        this.accountPaymentService = accountPaymentService;
+        this.contractService = contractService;
+    }
+
+    @Override
+    public String getFlowKey() {
+        return "after_sales_flow";
+    }
+
+    @Override
+    public Long start(Long flowId, JSONObject submitData) {
+        AfterSalesDto afterSalesDto = submitData.toJavaObject(AfterSalesDto.class);
+
+        afterSalesDto.setFlowId(flowId);
+
+        Long contractProductId = afterSalesDto.getContractProductId();
+        ContractProduct contractProduct = contractProductService.getById(contractProductId);
+        Assert.notEmpty(contractProduct, "查询不到订单产品信息!");
+
+        afterSalesDto.setCode(codingRuleService.createCode(CodingRuleEnum.AFTER_SALES.getKey(), null));
+
+        //赋值信息
+        afterSalesDto.setContractId(contractProduct.getContractId());
+        afterSalesDto.setProductId(contractProduct.getProductId());
+
+        afterSalesDto.setCompanyId(SecurityUtils.getCompanyId());
+
+        afterSalesService.save(afterSalesDto);
+
+        //回填数据
+        submitData.put("code", afterSalesDto.getCode());
+
+        return afterSalesDto.getId();
+    }
+
+    @Override
+    public void end(Long flowId, Long businessId, JSONObject submitData) {
+        AfterSales afterSales = afterSalesService.getById(businessId);
+        afterSales.setStatus(FlowStatusEnum1.PASS.getKey());
+        afterSalesService.updateById(afterSales);
+
+
+        Long contractProductId = afterSales.getContractProductId();
+        ContractProduct contractProduct = contractProductService.getById(contractProductId);
+        Assert.notEmpty(contractProduct, "查询不到合同产品明细信息!");
+
+        //计算售后价格
+        BigDecimal multiply = contractProduct.getPrice().multiply(afterSales.getQuantity());
+
+        //如果售后类型=仅退款30/退货退款40。审批通过后生成打款数据
+        if (ObjectUtil.equals(afterSales, 30) || ObjectUtil.equals(afterSales, 40)) {
+            // 添加一条付款流水
+            AccountPayment accountPayment = new AccountPayment();
+
+            SysUser sysUser = userService.getById(afterSales.getUserId());
+            if (ObjectUtil.isNotEmpty(sysUser)) {
+                accountPayment.setDepartmentId(sysUser.getDeptId());
+            }
+
+            accountPayment.setBusinessId(afterSales.getId());
+            accountPayment.setPaymentTime(new Date());
+            accountPayment.setCurrency("CNY");
+            accountPayment.setStatus(PaymentStatusEnum.UNDER_REVIEW.getKey());
+            accountPayment.setType(40);//售后
+            accountPayment.setPaymentRemark(afterSales.getRemark());
+            accountPayment.setIncomeAmount(multiply);
+            accountPayment.setName(afterSales.getAccountName());
+            accountPayment.setOpeningBank(afterSales.getOpeningBank());
+            accountPayment.setAccountOpening(afterSales.getAccountOpening());
+            accountPayment.setDataUser(afterSales.getUserId());
+            accountPayment.setAmount(BigDecimal.ZERO);
+            accountPayment.setCompanyId(afterSales.getCompanyId());
+
+            accountPaymentService.save(accountPayment);
+        }
+        //如果售后类型=补发10/换货20。审批通过后,生成一条销售订单,与原销售订单信息基本一致:商品清单只有这一条,数量=售后数量,价格=0。默认审批通过
+        if (ObjectUtil.equals(afterSales, 30) || ObjectUtil.equals(afterSales, 40)) {
+            Contract contract = contractService.getById(contractProduct.getContractId());
+            Assert.notEmpty(contract, "查询不到合同信息!");
+            contract.setId(null);
+            contract.setAmount(BigDecimal.ZERO);
+            contractService.save(contract);
+
+            ContractProduct contractProduct1 = contractProductService.getById(contractProductId);
+            contractProduct1.setId(null);
+            contractProduct1.setContractId(contract.getId());
+            contractProduct1.setPrice(BigDecimal.ZERO);
+            contractProduct1.setQuantity(afterSales.getQuantity());
+            contractProductService.save(contractProduct1);
+        }
+    }
+}

+ 1 - 1
hx-sale/src/main/java/com/fjhx/sale/flow/PayFlow.java

@@ -181,7 +181,7 @@ public class PayFlow extends FlowDelegate {
         //获取采购退货金额
         Map<Long, List<PurchaseBack>> purchaseBackMap = purchaseBackService.mapKGroup(PurchaseBack::getPurchaseId, q -> q
                 .in(PurchaseBack::getPurchaseId, purchaseIdList)
-                .in(PurchaseBack::getStatus, FlowStatusEnum1.PASS, FlowStatusEnum1.UPDATE_LOADING)
+                .in(PurchaseBack::getStatus, FlowStatusEnum1.PASS.getKey(), FlowStatusEnum1.UPDATE_LOADING.getKey())
         );
 
         for (EhsdPurchase purchase : purchaseList) {

+ 9 - 0
hx-sale/src/main/java/com/fjhx/sale/flow/PurchaseBackFlow.java

@@ -6,13 +6,16 @@ import com.fjhx.common.entity.AvailableStockBo;
 import com.fjhx.common.enums.CodingRuleEnum;
 import com.fjhx.common.enums.FlowStatusEnum1;
 import com.fjhx.common.service.coding.CodingRuleService;
+import com.fjhx.common.utils.Assert;
 import com.fjhx.flow.core.FlowDelegate;
 import com.fjhx.flow.enums.FlowStatusEnum;
 import com.fjhx.item.enums.ProductAvailableRecordType;
 import com.fjhx.item.service.product.ProductInfoService;
 import com.fjhx.sale.entity.purchase.dto.PurchaseBackDto;
+import com.fjhx.sale.entity.purchase.po.EhsdPurchase;
 import com.fjhx.sale.entity.purchase.po.PurchaseBack;
 import com.fjhx.sale.entity.purchase.po.PurchaseBackDetails;
+import com.fjhx.sale.service.purchase.EhsdPurchaseService;
 import com.fjhx.sale.service.purchase.PurchaseBackDetailsService;
 import com.fjhx.sale.service.purchase.PurchaseBackService;
 import com.fjhx.wms.entity.stock.emums.JournalType;
@@ -46,6 +49,8 @@ public class PurchaseBackFlow extends FlowDelegate {
     private StockWaitDetailsService stockWaitDetailsService;
     @Autowired
     private ProductInfoService productInfoService;
+    @Autowired
+    private EhsdPurchaseService ehsdPurchaseService;
 
     @Override
     public String getFlowKey() {
@@ -82,8 +87,12 @@ public class PurchaseBackFlow extends FlowDelegate {
         }
         purchaseBackDetailsService.saveOrUpdateBatch(purchaseBackDetailsList);
 
+        EhsdPurchase purchase = ehsdPurchaseService.getById(purchaseBackDto.getPurchaseId());
+        Assert.notEmpty(purchase, "查询不到采购信息!");
+
         //回传数据给流程引擎
         submitData.put("code", purchaseBackDto.getCode());
+        submitData.put("purchaseCode", purchase.getCode());
         submitData.put("amount", purchaseBackDto.getAmount());
 
         return purchaseBackDto.getId();

+ 3 - 1
hx-sale/src/main/java/com/fjhx/sale/service/dept/impl/DeptPerfServiceImpl.java

@@ -91,7 +91,9 @@ public class DeptPerfServiceImpl extends ServiceImpl<DeptPerfMapper, DeptPerf> i
             DeptPerf deptPerf = deptPerfMap.get(deptPerfReporting.getGroupId());
             if (ObjectUtil.isNotEmpty(deptPerf)) {
                 BigDecimal targetAmount = getTargetAmount(deptPerf, month);
-                deptPerfReporting.setTargetAmount(targetAmount.multiply(BigDecimal.valueOf(10000)));
+                if (ObjectUtil.isNotEmpty(targetAmount)) {
+                    deptPerfReporting.setTargetAmount(targetAmount.multiply(BigDecimal.valueOf(10000)));
+                }
             }
 
             //赋值完成率

+ 2 - 2
hx-sale/src/main/java/com/fjhx/sale/service/purchase/impl/EhsdPurchaseServiceImpl.java

@@ -201,7 +201,7 @@ public class EhsdPurchaseServiceImpl extends ServiceImpl<EhsdPurchaseMapper, Ehs
         //赋值采购退货金额
         Map<Long, List<PurchaseBack>> purchaseBackMap = purchaseBackService.mapKGroup(PurchaseBack::getPurchaseId, q -> q
                 .in(PurchaseBack::getPurchaseId, pids)
-                .in(PurchaseBack::getStatus, FlowStatusEnum1.PASS, FlowStatusEnum1.UPDATE_LOADING)
+                .in(PurchaseBack::getStatus, FlowStatusEnum1.PASS.getKey(), FlowStatusEnum1.UPDATE_LOADING.getKey())
         );
         for (EhsdPurchaseVo record : records) {
             //赋值退货金额、应付金额
@@ -602,7 +602,7 @@ public class EhsdPurchaseServiceImpl extends ServiceImpl<EhsdPurchaseMapper, Ehs
         //赋值采购退货金额
         Map<Long, List<PurchaseBack>> purchaseBackMap = purchaseBackService.mapKGroup(PurchaseBack::getPurchaseId, q -> q
                 .in(PurchaseBack::getPurchaseId, ids)
-                .in(PurchaseBack::getStatus, FlowStatusEnum1.PASS, FlowStatusEnum1.UPDATE_LOADING)
+                .in(PurchaseBack::getStatus, FlowStatusEnum1.PASS.getKey(), FlowStatusEnum1.UPDATE_LOADING.getKey())
         );
 
         List<InvoiceDetailsVo> invoiceDetailsList = invoiceDetailsService.getSumMoneyByPurchaseIds(ids);