|
@@ -3,13 +3,20 @@ package com.zfire.mall.manager.logic.k3;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
import com.zfire.mall.manager.bean.k3.KingDeePurchaseStockOutAdd;
|
|
|
import com.zfire.mall.manager.bean.k3.KingDeePurchaseStockOutData;
|
|
|
-import com.zfire.mall.manager.plus.entity.KingDeePurchaseStockOut;
|
|
|
-import com.zfire.mall.manager.plus.entity.KingDeePurchaseStockOutItem;
|
|
|
+import com.zfire.mall.manager.exception.RemoteServiceException;
|
|
|
+import com.zfire.mall.manager.logic.stock.StockCommonLogic;
|
|
|
+import com.zfire.mall.manager.plus.entity.*;
|
|
|
import com.zfire.mall.manager.plus.service.KingDeePurchaseStockOutItemService;
|
|
|
import com.zfire.mall.manager.plus.service.KingDeePurchaseStockOutService;
|
|
|
+import com.zfire.mall.manager.plus.service.StockService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
|
|
|
@Service
|
|
|
@Slf4j
|
|
@@ -21,6 +28,13 @@ public class K3PurchaseStockOutLogic {
|
|
|
@Autowired
|
|
|
KingDeePurchaseStockOutService kingDeePurchaseStockOutService;
|
|
|
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ StockService stockService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ StockCommonLogic stockCommonLogic;
|
|
|
+
|
|
|
public void add(KingDeePurchaseStockOutAdd kingDeePurchaseStockInAdd) {
|
|
|
kingDeePurchaseStockInAdd.setId(IdWorker.getIdStr());
|
|
|
kingDeePurchaseStockInAdd.setBillNo(IdWorker.getIdStr());
|
|
@@ -50,10 +64,37 @@ public class K3PurchaseStockOutLogic {
|
|
|
kingDeePurchaseStockOutItemService.saveBatch(kingDeePurchaseStockInAdd.getKingDeePurchaseStockOutItems());
|
|
|
}
|
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public void examine(String billNo, String cancelStatus) {
|
|
|
KingDeePurchaseStockOut kingDeePurchaseStockOut = kingDeePurchaseStockOutService.getById(billNo);
|
|
|
kingDeePurchaseStockOut.setCancelStatus(cancelStatus);
|
|
|
kingDeePurchaseStockOut.updateById();
|
|
|
+
|
|
|
+ List<KingDeePurchaseStockOutItem> kingDeePurchaseStockOutItems = kingDeePurchaseStockOutItemService.lambdaQuery().eq(KingDeePurchaseStockOutItem::getBillNo, billNo).list();
|
|
|
+ for (KingDeePurchaseStockOutItem kingDeePurchaseStockOutItem : kingDeePurchaseStockOutItems) {
|
|
|
+ this.stockSub(kingDeePurchaseStockOut,kingDeePurchaseStockOutItem);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void stockSub(KingDeePurchaseStockOut kingDeePurchaseStockOut, KingDeePurchaseStockOutItem kingDeePurchaseStockOutItem) {
|
|
|
+
|
|
|
+ Stock stock = stockService.lambdaQuery().eq(Stock::getStockId, kingDeePurchaseStockOutItem.getStockId())
|
|
|
+ .eq(Stock::getMaterialId, kingDeePurchaseStockOutItem.getMaterialId()).last("limit 1").one();
|
|
|
+
|
|
|
+ if (stock == null)
|
|
|
+ throw new RemoteServiceException(kingDeePurchaseStockOutItem.getMaterialName()+"该物料没有库存,不能退库");
|
|
|
+
|
|
|
+
|
|
|
+ stockCommonLogic.stockAccLog("采购退料单减少库存",stock,kingDeePurchaseStockOutItem.getRmRealQty(),kingDeePurchaseStockOutItem.getBillNo(),false,"采购退料单");
|
|
|
+
|
|
|
+ stock.setStockQty(stock.getStockQty().subtract(kingDeePurchaseStockOutItem.getRmRealQty()));
|
|
|
+
|
|
|
+ if (stock.getStockQty().doubleValue() < 1)
|
|
|
+ throw new RemoteServiceException(kingDeePurchaseStockOutItem.getMaterialName()+"该物料没有库存,不能退库");
|
|
|
+
|
|
|
+ stock.updateById();
|
|
|
+
|
|
|
}
|
|
|
|
|
|
public KingDeePurchaseStockOutData detail(String id) {
|