yuj пре 7 година
родитељ
комит
ad6b2cf4ff

+ 13 - 3
src/main/java/com/uas/platform/b2c/prod/commodity/service/impl/CommodityInOutboundServiceImpl.java

@@ -1,5 +1,6 @@
 package com.uas.platform.b2c.prod.commodity.service.impl;
 
+import com.uas.platform.b2c.common.account.model.User;
 import com.uas.platform.b2c.core.support.SystemSession;
 import com.uas.platform.b2c.core.utils.NumberUtil;
 import com.uas.platform.b2c.core.utils.StringUtilB2C;
@@ -179,6 +180,7 @@ public class CommodityInOutboundServiceImpl implements CommodityInOutboundServic
                 }
                 prids.add(inOutboundDetail.getProductId());
             }
+            User user = SystemSession.getUser();
             String inOutboundId = createNumberService.generateOrderNumber(com.uas.platform.b2c.core.constant.EncodingRulesConstant.INOUTBOUND_NUM, "trade$commodity_in_outbound", 8);
             CommodityInOutbound inOutbound = new CommodityInOutbound(type);
             inOutbound.setInOutId(inOutboundId);
@@ -188,18 +190,26 @@ public class CommodityInOutboundServiceImpl implements CommodityInOutboundServic
                 List<Product> products = productService.findByProductId(prids);
                 for (InOutboundDetail inOutboundDetail : detaiList) {
                     for (Product product : products) {
+                        if (user.getEnterprise().getUu().longValue() != product.getEnUU().longValue()) {
+                            throw new IllegalOperatorException("型号:" + product.getPcmpcode() + ",品牌:" +product.getPbranden()+"不属于本公司,不能做出入库");
+                        }
                         if (inOutboundDetail.getProductId().longValue() == product.getId().longValue()) {
                             if (InOutBoundType.INBOUND.equals(type) || InOutBoundType.OTHER_INBOUND.equals(type) || InOutBoundType.PURCHASE_INBOUND.equals(type)) {
+                                //只有入库会影响成本单价
+                                if (NumberUtil.compare(inOutboundDetail.getPrice(), DoubleConstant.zero) > 0 && NumberUtil.compare(product.getPrice(), DoubleConstant.zero) > 0) {
+                                    product.setPrice(NumberUtil.div(NumberUtil.add(NumberUtil.mul(product.getPrice(), product.getErpReserve()), NumberUtil.mul(inOutboundDetail.getPrice(), inOutboundDetail.getQty())), NumberUtil.add(product.getErpReserve(), inOutboundDetail.getQty())));
+
+
+                                }
                                 product.setErpReserve(NumberUtil.add(product.getErpReserve(), inOutboundDetail.getQty()));
                             } else {
                                 //出库
                                 if (NumberUtil.compare(product.getErpReserve(), DoubleConstant.zero) == 0) {
-                                    break;
+                                    throw new IllegalOperatorException("型号:" + product.getPcmpcode() + ",品牌:" +product.getPbranden()+"的物料为0,不能做出库");
                                 } else if (NumberUtil.compare(product.getErpReserve(), inOutboundDetail.getQty()) > 0) {
                                     product.setErpReserve(NumberUtil.sub(product.getErpReserve(), inOutboundDetail.getQty()));
                                 } else {
-                                    inOutboundDetail.setQty(product.getErpReserve());
-                                    product.setErpReserve(DoubleConstant.zero);
+                                    throw new IllegalOperatorException("型号:" + product.getPcmpcode() + ",品牌:" +product.getPbranden()+"的物料库存数为"+product.getErpReserve() + "出库数是:"+inOutboundDetail.getQty()+"不能做出库");
                                 }
 
                             }

+ 1 - 50
src/main/java/com/uas/platform/b2c/prod/commodity/service/impl/ProductServiceImpl.java

@@ -2293,62 +2293,13 @@ public class ProductServiceImpl implements ProductService {
             return;
         } else {
             List<Product> products = productDao.findProductInId(prids);
-            Set<Long> idSet = new HashSet<>();
-            idSet.addAll(prids);
-            List<InOutboundDetail> inOutboundDetails = inOutboundDetailService.findByProductId(idSet);
-            Map<Long, List<Double>> map = new HashMap<>();
-            Double qtyContainPrice = 0.0d;
-            Double qty = 0.0d;
-            Double totalPrice = 0.0d;
-            List<Double> doubleList = null;
-            for (InOutboundDetail inOutboundDetail : inOutboundDetails) {
-                doubleList = map.get(inOutboundDetail.getProductId());
-                qtyContainPrice = 0.0d; qty = 0.0d; totalPrice = 0.0d;
-                if (doubleList == null) {
-                    doubleList = new ArrayList<>();
-                    doubleList.add(qtyContainPrice);
-                    doubleList.add(qty);
-                    doubleList.add(totalPrice);
-                } else {
-                    qtyContainPrice = doubleList.get(0);
-                    qty = doubleList.get(1);
-                    totalPrice = doubleList.get(2);
-                }
-                if (InOutBoundType.INBOUND.equals(inOutboundDetail.getCommodityInOutbound().getType())) {
-                    qty = NumberUtil.add(qty, inOutboundDetail.getQty());
-                    if (inOutboundDetail.getPrice() != null) {
-                        qtyContainPrice = NumberUtil.add(qtyContainPrice, inOutboundDetail.getQty());
-                        totalPrice = NumberUtil.add(totalPrice, NumberUtil.mul(inOutboundDetail.getPrice(), inOutboundDetail.getQty()));
-                    }
-                } else {
-                    qty = NumberUtil.sub(qty, inOutboundDetail.getQty());
-                }
-                doubleList.set(0, qtyContainPrice);
-                doubleList.set(1, qty);
-                doubleList.set(2, totalPrice);
-                map.put(inOutboundDetail.getProductId(), doubleList);
-            }
-
-            for (Product product : products) {
-                List<Double> list = map.get(product.getId());
-                if (CollectionUtils.isNotEmpty(list)) {
-                    qty = list.get(1);
-                    if (NumberUtil.compare(qty, DoubleConstant.zero) < 1) {
-                        product.setErpReserve(DoubleConstant.zero);
-                    } else {
-                        product.setErpReserve(qty);
-                    }
-                    double price = NumberUtil.div(list.get(2), list.get(0));
-                    product.setPrice(price);
-                }
-            }
-
             List<Goods> goodsList = goodsService.findByProductids(prids);
             for (Product product : products) {
                 for (Goods goods : goodsList) {
                     if (goods.getProductid().longValue() == product.getId().longValue()) {
                         goods.setReserve(product.getErpReserve());
                         goods.setStatus();
+                        break;
                     }
                 }
             }