Browse Source

采购退货功能修改

yzc 1 year ago
parent
commit
58d3bdf4b3

+ 9 - 0
hx-sale/src/main/java/com/fjhx/sale/entity/purchase/po/PurchaseBack.java

@@ -5,6 +5,8 @@ import com.ruoyi.common.core.domain.BasePo;
 import lombok.Getter;
 import lombok.Setter;
 
+import java.math.BigDecimal;
+
 /**
  * <p>
  * sale_采购退货
@@ -43,4 +45,11 @@ public class PurchaseBack extends BasePo {
      */
     private Long companyId;
 
+    /**
+     * 退货金额
+     */
+    private BigDecimal amount;
+
+    private Long flowId;
+
 }

+ 2 - 2
hx-sale/src/main/java/com/fjhx/sale/entity/purchase/po/PurchaseBackDetails.java

@@ -46,9 +46,9 @@ public class PurchaseBackDetails extends BasePo {
     private BigDecimal quantity;
 
     /**
-     * 金额
+     * 单价
      */
-    private BigDecimal amount;
+    private BigDecimal price;
 
     /**
      * 备注

+ 74 - 64
hx-sale/src/main/java/com/fjhx/sale/entity/purchase/vo/EhsdPurchaseVo.java

@@ -20,71 +20,71 @@ import java.util.List;
 @Setter
 public class EhsdPurchaseVo extends EhsdPurchase {
 
-	/**
-	 * 历史毛利信息
-	 */
-	List<ContractBudgetVo.GrossProfitInfo> grossProfitInfoList;
-	/**
-	 * 采购商品列表
-	 */
-	private List<EhsdPurchaseProductVo> purchaseProductList;
-	/**
-	 * 装箱明细
-	 */
-	private List<PackDetailProductVo> packDetailProductList;
-	/**
-	 * 买方名称
-	 */
-	private String buyCorporationName;
-	/**
-	 * 卖方名称
-	 */
-	private String sellCorporationName;
-	/**
-	 * 卖方国家表名称
-	 */
-	private String sellCountryName;
-	/**
-	 * 卖方省份名称
-	 */
-	private String sellProvinceName;
-	/**
-	 * 卖方城市名称
-	 */
-	private String sellCityName;
-	/**
-	 * 开户银行
-	 */
-	private String openingBank;
-	/**
-	 * 账户名
-	 */
-	private String openingName;
-	/**
-	 * 联系人
-	 */
-	private String contactPerson;
-	/**
-	 * 账户
-	 */
-	private String accountOpening;
-	/**
-	 * 流程Id
-	 */
-	private Long flowId;
-	/**
-	 * 发票总金额
-	 */
-	private BigDecimal sumInvoiceMoney;
-	/**
-	 * 付款总金额
-	 */
-	private BigDecimal sumPayMoney;
+    /**
+     * 历史毛利信息
+     */
+    List<ContractBudgetVo.GrossProfitInfo> grossProfitInfoList;
+    /**
+     * 采购商品列表
+     */
+    private List<EhsdPurchaseProductVo> purchaseProductList;
+    /**
+     * 装箱明细
+     */
+    private List<PackDetailProductVo> packDetailProductList;
+    /**
+     * 买方名称
+     */
+    private String buyCorporationName;
+    /**
+     * 卖方名称
+     */
+    private String sellCorporationName;
+    /**
+     * 卖方国家表名称
+     */
+    private String sellCountryName;
+    /**
+     * 卖方省份名称
+     */
+    private String sellProvinceName;
+    /**
+     * 卖方城市名称
+     */
+    private String sellCityName;
+    /**
+     * 开户银行
+     */
+    private String openingBank;
+    /**
+     * 账户名
+     */
+    private String openingName;
+    /**
+     * 联系人
+     */
+    private String contactPerson;
+    /**
+     * 账户
+     */
+    private String accountOpening;
+    /**
+     * 流程Id
+     */
+    private Long flowId;
+    /**
+     * 发票总金额
+     */
+    private BigDecimal sumInvoiceMoney;
+    /**
+     * 付款总金额
+     */
+    private BigDecimal sumPayMoney;
 
-	/**
-	 * 创建人名称
-	 */
-	private String createUserName;
+    /**
+     * 创建人名称
+     */
+    private String createUserName;
 
     /**
      * 创建人手机
@@ -102,4 +102,14 @@ public class EhsdPurchaseVo extends EhsdPurchase {
      * 到货明细记录
      */
     private List<ArrivalDetailVo> arrivalDetailList;
+
+    /**
+     * 退货金额
+     */
+    private BigDecimal backAmount;
+
+    /**
+     * 应付金额
+     */
+    private BigDecimal payableAmount;
 }

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

@@ -55,6 +55,7 @@ public class PurchaseBackFlow extends FlowDelegate {
     @Override
     public Long start(Long flowId, JSONObject submitData) {
         PurchaseBackDto purchaseBackDto = submitData.toJavaObject(PurchaseBackDto.class);
+        purchaseBackDto.setFlowId(flowId);
 
         if (ObjectUtil.isEmpty(purchaseBackDto.getCompanyId())) {
             purchaseBackDto.setCompanyId(SecurityUtils.getCompanyId());
@@ -81,8 +82,10 @@ public class PurchaseBackFlow extends FlowDelegate {
         }
         purchaseBackDetailsService.saveOrUpdateBatch(purchaseBackDetailsList);
 
-        //回传单号
+        //回传数据给流程引擎
         submitData.put("code", purchaseBackDto.getCode());
+        submitData.put("amount", purchaseBackDto.getAmount());
+
         return purchaseBackDto.getId();
     }
 

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

@@ -53,10 +53,7 @@ import com.fjhx.sale.entity.pack.po.PackDetailProduct;
 import com.fjhx.sale.entity.pack.vo.PackDetailProductVo;
 import com.fjhx.sale.entity.purchase.dto.EhsdPurchaseDto;
 import com.fjhx.sale.entity.purchase.dto.EhsdPurchaseSelectDto;
-import com.fjhx.sale.entity.purchase.po.EhsdPurchase;
-import com.fjhx.sale.entity.purchase.po.EhsdPurchaseProduct;
-import com.fjhx.sale.entity.purchase.po.EhsdPurchaseProductMountings;
-import com.fjhx.sale.entity.purchase.po.EhsdPurchaseProject;
+import com.fjhx.sale.entity.purchase.po.*;
 import com.fjhx.sale.entity.purchase.vo.EhsdPurchaseDocumentaryVo;
 import com.fjhx.sale.entity.purchase.vo.EhsdPurchaseProductVo;
 import com.fjhx.sale.entity.purchase.vo.EhsdPurchaseVo;
@@ -66,10 +63,7 @@ import com.fjhx.sale.mapper.purchase.EhsdPurchaseProductMapper;
 import com.fjhx.sale.service.contract.ContractService;
 import com.fjhx.sale.service.pack.PackDetailProductService;
 import com.fjhx.sale.service.pack.PackDetailService;
-import com.fjhx.sale.service.purchase.EhsdPurchaseProductMountingsService;
-import com.fjhx.sale.service.purchase.EhsdPurchaseProductService;
-import com.fjhx.sale.service.purchase.EhsdPurchaseProjectService;
-import com.fjhx.sale.service.purchase.EhsdPurchaseService;
+import com.fjhx.sale.service.purchase.*;
 import com.fjhx.supply.entity.supplier.po.SupplierInfo;
 import com.fjhx.supply.entity.supplier.po.SupplierPrice;
 import com.fjhx.supply.entity.supplier.vo.SupplierPriceVo;
@@ -77,7 +71,6 @@ import com.fjhx.supply.service.supplier.SupplierInfoService;
 import com.fjhx.supply.service.supplier.SupplierPriceService;
 import com.fjhx.tenant.utils.DeptUstil;
 import com.fjhx.wms.entity.stock.po.StockWait;
-import com.fjhx.wms.service.stock.StockWaitDetailsService;
 import com.fjhx.wms.service.stock.StockWaitService;
 import com.ruoyi.common.core.domain.BasePo;
 import com.ruoyi.common.core.domain.BaseSelectDto;
@@ -155,7 +148,7 @@ public class EhsdPurchaseServiceImpl extends ServiceImpl<EhsdPurchaseMapper, Ehs
     @Autowired
     private EhsdPurchaseProductMapper ehsdPurchaseProductMapper;
     @Autowired
-    private StockWaitDetailsService stockWaitDetailsService;
+    private PurchaseBackService purchaseBackService;
 
     /**
      * 分页
@@ -182,8 +175,8 @@ public class EhsdPurchaseServiceImpl extends ServiceImpl<EhsdPurchaseMapper, Ehs
         }
 
         //权限过滤:采购
-            wrapper.in("t1", EhsdPurchase::getCompanyId, SecurityUtils.getCompanyIds());
-            wrapper.eq("t1", EhsdPurchase::getCompanyId, dto.getCompanyId());
+        wrapper.in("t1", EhsdPurchase::getCompanyId, SecurityUtils.getCompanyIds());
+        wrapper.eq("t1", EhsdPurchase::getCompanyId, dto.getCompanyId());
 
 
         wrapper.orderByDesc("t1", EhsdPurchase::getCreateTime);
@@ -199,15 +192,33 @@ public class EhsdPurchaseServiceImpl extends ServiceImpl<EhsdPurchaseMapper, Ehs
         //  赋值流程id
         flowExampleService.setFlowId(records, EhsdPurchaseVo::setFlowId);
 
-        //赋值付款金额
+        //赋值付款金额
         List<Long> pids = records.stream().map(EhsdPurchaseVo::getId).collect(Collectors.toList());
         List<PayDetailVo> payDetailVoList = payDetailService.getSumMoneyByPurchaseIds(pids);
         Map<Long, BigDecimal> payMap = payDetailVoList.stream().collect(Collectors.toMap(PayDetailVo::getPurchaseId, PayDetailVo::getSumMoney));
         records.forEach(item -> item.setSumPayMoney(payMap.getOrDefault(item.getId(), BigDecimal.ZERO)));
 
+        //赋值采购退货金额
+        Map<Long, List<PurchaseBack>> purchaseBackMap = purchaseBackService.mapKGroup(PurchaseBack::getPurchaseId, q -> q
+                .in(PurchaseBack::getPurchaseId, pids)
+                .in(PurchaseBack::getStatus, FlowStatusEnum1.PASS, FlowStatusEnum1.UPDATE_LOADING)
+        );
+        for (EhsdPurchaseVo record : records) {
+            //赋值退货金额、应付金额
+            List<PurchaseBack> purchaseBackList = purchaseBackMap.getOrDefault(record.getId(), new ArrayList<>());
+            BigDecimal backAmount = purchaseBackList.stream().map(PurchaseBack::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
+            record.setBackAmount(backAmount);
+            record.setPayableAmount(record.getAmount().subtract(backAmount));
+        }
+
         //赋值用户名称
         UserUtil.assignmentNickName(records, EhsdPurchase::getCreateUser, EhsdPurchase::setUserName);
 
+        //赋值供应商名称
+        supplierInfoService.attributeAssign(records, EhsdPurchase::getSellCorporationId, (item, supply) -> {
+            item.setSellCorporationName(supply.getName());
+        });
+
         //获取生产公司信息
         List<Long> companyIds = records.stream().map(EhsdPurchase::getCompanyId).collect(Collectors.toList());
         Map<Long, String> companyNameMap = DeptUstil.getDeptNameMap(companyIds);
@@ -587,6 +598,13 @@ public class EhsdPurchaseServiceImpl extends ServiceImpl<EhsdPurchaseMapper, Ehs
 
         List<EhsdPurchaseVo> ehsdPurchases = BeanUtil.copyToList(list, EhsdPurchaseVo.class);
         List<Long> ids = list.stream().distinct().map(EhsdPurchase::getId).collect(Collectors.toList());
+
+        //赋值采购退货金额
+        Map<Long, List<PurchaseBack>> purchaseBackMap = purchaseBackService.mapKGroup(PurchaseBack::getPurchaseId, q -> q
+                .in(PurchaseBack::getPurchaseId, ids)
+                .in(PurchaseBack::getStatus, FlowStatusEnum1.PASS, FlowStatusEnum1.UPDATE_LOADING)
+        );
+
         List<InvoiceDetailsVo> invoiceDetailsList = invoiceDetailsService.getSumMoneyByPurchaseIds(ids);
         Map<Long, BigDecimal> invoiceMap = invoiceDetailsList.stream().collect(Collectors.toMap(InvoiceDetailsVo::getPurchaseId, InvoiceDetailsVo::getSumMoney));
         List<PayDetailVo> payDetailVoList = payDetailService.getSumMoneyByPurchaseIds(ids);
@@ -602,6 +620,12 @@ public class EhsdPurchaseServiceImpl extends ServiceImpl<EhsdPurchaseMapper, Ehs
             } else {
                 p.setSumPayMoney(BigDecimal.ZERO);
             }
+
+            //赋值退货金额、应付金额
+            List<PurchaseBack> purchaseBackList = purchaseBackMap.getOrDefault(p.getId(), new ArrayList<>());
+            BigDecimal backAmount = purchaseBackList.stream().map(PurchaseBack::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
+            p.setBackAmount(backAmount);
+            p.setPayableAmount(p.getAmount().subtract(backAmount));
         }
 
         return ehsdPurchases;

+ 2 - 0
hx-sale/src/main/resources/mapper/purchase/PurchaseBackMapper.xml

@@ -11,6 +11,8 @@
                pb.create_time,
                pb.update_user,
                pb.update_time,
+               pb.amount,
+               pb.company_id,
                p.`code` AS purchaseCode
         FROM purchase_back pb
                  LEFT JOIN ehsd_purchase p ON pb.purchase_id = p.id