Explorar o código

Merge branch 'master' of http://git.dongkesoft.com:9001/iBOSS-2.0-Mini/iboss-server-mdm

zhoux hai 1 ano
pai
achega
a0fa148fda

+ 18 - 6
src/main/java/com/dk/mdm/mapper/report/ReportMapper.xml

@@ -3074,10 +3074,16 @@
         select
         <include refid="getSaleProfitInOutBound"/>
         from dkic_b.t_psi_in_out_record tpr
-        where tpr.cp_id = #{cpId}
-        <if test="makeTimeStart != null and makeTimeEnd != null">
-            AND tpr.op_create_time &gt;= #{makeTimeStart}::timestamp with time zone
-            AND tpr.op_create_time &lt; #{makeTimeEnd}::timestamp with time zone + interval '1 day'
+        <if test="orgIds!=null and orgIds.size()>0">
+            left join dkic_b.t_psi_inbound tpi on tpi.into_id = biznis_id
+            left join dkic_b.t_psi_outbound tpo on tpo.out_id = biznis_id
+        </if>
+        <include refid="getSaleProfitCond"/>
+        <if test="orgIds!=null and orgIds.size()>0">
+            and (
+            (tpo.org_id = any(#{orgIds, typeHandler=UuidListTypeHanlder}) and tpi.org_id is null)
+            or (tpi.org_id = any(#{orgIds, typeHandler=UuidListTypeHanlder}) and tpo.org_id is null)
+            )
         </if>
         ) t
     </select>
@@ -3137,6 +3143,12 @@
         left join dkic_b.t_psi_inbound tpi on tpi.into_id = biznis_id
         left join dkic_b.t_psi_outbound tpo on tpo.out_id = biznis_id
         <include refid="getSaleProfitCond"/>
+        <if test="orgIds!=null and orgIds.size()>0">
+            and (
+            (tpo.org_id = any(#{orgIds, typeHandler=UuidListTypeHanlder}) and tpi.org_id is null)
+            or (tpi.org_id = any(#{orgIds, typeHandler=UuidListTypeHanlder}) and tpo.org_id is null)
+            )
+        </if>
         group by coalesce(tpi.staff_id, tpo.staff_id)) t
         ) tt
         left join dkic_b.t_mst_staff tms on tms.staff_id = tt.staff_id
@@ -3180,10 +3192,10 @@
             order by tt.profit desc
         </if>
         <if test="orderBy != null and orderBy=='rateAsc'">
-            order by tt.profitRate
+            order by tt."profitRate"
         </if>
         <if test="orderBy != null and orderBy=='rateDsc'">
-            order by tt.profitRate desc
+            order by tt."profitRate" desc
         </if>
         <if test="limit!=null and limit">
             limit 5

+ 2 - 1
src/main/java/com/dk/mdm/mapper/sale/OrderMapper.xml

@@ -540,7 +540,8 @@
                makestaff.staff_name                              as "makeStaffName",
                t.make_time,
                t.cp_id,
-               t.flg_valid
+               t.flg_valid,
+               t.fact_amt
         FROM dkic_b.t_psi_order as t
                  left join dkic_b.t_mst_sale_channel tmsc on t.sales_channel = tmsc.channel_id
                  left join dkic_b.t_mst_org tmo on t.org_id = tmo.org_id

+ 5 - 0
src/main/java/com/dk/mdm/model/vo/ivt/OutboundVO.java

@@ -48,6 +48,11 @@ public class OutboundVO{
     @Excel(name = "收款金额")
     @ApiModelProperty(value = "收款金额")
     private BigDecimal sumAmtRec;
+    /**
+     * 合计金额
+     */
+    @ApiModelProperty(value = "合计金额")
+    private BigDecimal sumAmount;
 
     /**
      * 实际金额

+ 31 - 14
src/main/java/com/dk/mdm/service/ivt/outbound/OutboundSaleOrderService.java

@@ -148,12 +148,6 @@ public class OutboundSaleOrderService extends BaseService<Outbound> {
                     .setWhId(outboundItemVO.getWhId())
                     .setNonStdCode(outboundItemVO.getNonStdCode()));
         }
-        //库存不存在
-        if(inventoryResponse ==null){
-            //当前出库商品中在库存中不存在
-            throw new BaseBusinessException(ErrorCodeEnum.SKU_IS_NOT_IN_INVENTORY.getCode(),
-                    ErrorCodeEnum.SKU_IS_NOT_IN_INVENTORY.getMessage());
-        }
         return inventoryResponse;
     }
     
@@ -193,16 +187,24 @@ public class OutboundSaleOrderService extends BaseService<Outbound> {
                 if(outboundItemVO.getSkuId()!=null){
                     //查询库存是否存在
                     InventoryResponse inventoryResponse = this.checkInventoryExist(outboundItemVO);
-                    BigDecimal invQty = inventoryResponse.getInvQty().subtract(outboundItemVO.getOutingQty());
-                    // (库存量  大于等于  本次出库数量不用做任何处理)
-                    //库存量 小于  本次出库数量
-                    if (invQty.compareTo(BigDecimal.ZERO) < 0) {
-                        outboundItemVO.setOutingQty(inventoryResponse.getInvQty());
+                    if (inventoryResponse != null) {
+                        BigDecimal invQty = inventoryResponse.getInvQty().subtract(outboundItemVO.getOutingQty());
+                        // (库存量  大于等于  本次出库数量不用做任何处理)
+                        //库存量 小于  本次出库数量
+                        if (invQty.compareTo(BigDecimal.ZERO) < 0) {
+                            outboundItemVO.setOutingQty(inventoryResponse.getInvQty());
+                            //不够库存数量----新建出库中数量
+                            outboundItemVO.setNotEnoughInventoryQty(invQty.abs());
+                        }
+                    } else {
                         //不够库存数量----新建出库中数量
-                        outboundItemVO.setNotEnoughInventoryQty(invQty.abs());
+                        outboundItemVO.setNotEnoughInventoryQty(outboundItemVO.getOutingQty());
                     }
                 }
             }
+            //过滤出库存量足够的数据
+            List<OutboundItemVO> itemList = outboundVO.getItemList().stream().filter(it -> it.getNotEnoughInventoryQty()==null ).collect(Collectors.toList());
+
             //region  过滤出不够出库的每条明细数量  ------新建出库中数据
             List<OutboundItemVO> outboundIngList = outboundVO.getItemList().stream().filter(it -> it.getNotEnoughInventoryQty()!=null && it.getNotEnoughInventoryQty().compareTo(BigDecimal.ZERO)>0).collect(Collectors.toList());
             if(outboundIngList != null && outboundIngList.size()>0){
@@ -215,8 +217,11 @@ public class OutboundSaleOrderService extends BaseService<Outbound> {
 
             //region  库存够扣减的明细  -----------新建已出库数据并扣减库存
             //销售出库新建
+            outboundVO.setFlgAutoHandle(true);
+            outboundVO.setItemList(itemList);
             this.saleOrderOutboundInsert(outboundVO,true);
             //endregion
+
         }
     }
     /*****************************************先判断库存*****************************************/
@@ -320,6 +325,7 @@ public class OutboundSaleOrderService extends BaseService<Outbound> {
                             .setFromItemId(outboundItemVO.getFromItemId())
                             .setPriceInto(outboundItemVO.getPriceOut())
                             .setIntoQty(outboundItemVO.getOutQty())
+                            .setIntoAmt(outboundItemVO.getOutAmt())
                             .setIntoAmt(costAmount)
                             .setIntoingQty(BigDecimal.ZERO)
                             .setIntoingAmt(BigDecimal.ZERO)
@@ -390,6 +396,14 @@ public class OutboundSaleOrderService extends BaseService<Outbound> {
         //endregion
 
         //region  总单
+        //出库数量
+        BigDecimal sumIntoQty = BigDecimal.ZERO;
+        //出库金额
+        BigDecimal sumIntoPriceAmt = BigDecimal.ZERO;
+        if(orderTransmitFlag){
+            sumIntoQty = outboundVO.getItemList().stream().map(OutboundItemVO::getOutingQty).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
+            sumIntoPriceAmt = outboundVO.getItemList().stream().map(OutboundItemVO::getPriceOut).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, BigDecimal.ROUND_HALF_UP);
+        }
         //获取 id/单号
         Map<String, Object> codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.SALEORDER.getName(), false);
         outboundVO.setOutId(codeMap.get("outId").toString()).
@@ -407,8 +421,8 @@ public class OutboundSaleOrderService extends BaseService<Outbound> {
         //出库状态等于已出库 更新合计出库数量/金额 = 出库中数量/出库中金额
         if (Constant.OutStatus.YICHUKU.getName().equals(outboundVO.getOutStatus())) {
             outboundVO
-                    .setOutQty(outboundVO.getOutingQty())
-                    .setOutAmt(outboundVO.getOutingAmt())
+                    .setOutQty(orderTransmitFlag ? sumIntoQty : outboundVO.getOutingQty())
+                    .setOutAmt(orderTransmitFlag ? sumIntoQty.multiply(sumIntoPriceAmt) : outboundVO.getOutingAmt())
                     .setOutingQty(BigDecimal.ZERO)
                     .setOutingAmt(BigDecimal.ZERO)
             ;
@@ -416,6 +430,9 @@ public class OutboundSaleOrderService extends BaseService<Outbound> {
             outboundVO
                     .setOutQty(BigDecimal.ZERO)
                     .setOutAmt(BigDecimal.ZERO)
+                    //用于销售订单自动创建出库单
+                    .setOutingQty(orderTransmitFlag ? sumIntoQty : outboundVO.getOutingQty())
+                    .setOutingAmt(orderTransmitFlag ? sumIntoQty.multiply(sumIntoPriceAmt) : outboundVO.getOutingAmt())
             ;
         }
 

+ 2 - 2
src/main/java/com/dk/mdm/service/report/ReportService.java

@@ -988,7 +988,7 @@ public class ReportService {
     public ResponseResultVO<Map<String, Object>> getSaleProfitGroupByStaff(Map<String, Object> param) {
         Map<String, Object> res = new HashMap<>();
         res.put("profit", reportMapper.getSaleProfit(param));
-        res.put("orgProfit", reportMapper.getSaleProfitGroupByStaff(param));
+        res.put("staffProfit", reportMapper.getSaleProfitGroupByStaff(param));
         return ResponseResultUtil.success(res);
     }
 
@@ -1000,7 +1000,7 @@ public class ReportService {
     public ResponseResultVO<Map<String, Object>> getSaleProfitGroupBySku(Map<String, Object> param) {
         Map<String, Object> res = new HashMap<>();
         res.put("profit", reportMapper.getSaleProfit(param));
-        res.put("orgProfit", reportMapper.getSaleProfitGroupBySku(param));
+        res.put("skuProfit", reportMapper.getSaleProfitGroupBySku(param));
         return ResponseResultUtil.success(res);
     }
 }

+ 11 - 0
src/main/java/com/dk/mdm/service/sale/OrderService.java

@@ -297,6 +297,12 @@ public class OrderService extends BaseService<Order> {
             for (OrderItemVO orderItemVO : orderVO.getItemList()) {
                 OrderItem orderItem = orderItemConvert.convertToPo(orderItemVO);
                 orderItem.setOrderId(order.getOrderId()).setCpId(order.getCpId()).setOutStatus(Constant.OutStatus.DAICHUKU.getName());
+               if( orderItem.getPriceStd()==null){
+                 orderItem.setPriceStd(BigDecimal.ZERO);
+               }
+                if( orderItem.getAmtStd()==null){
+                    orderItem.setAmtStd(BigDecimal.ZERO);
+                }
                 orderItem.setItemId(UUID.randomUUID().toString());
                 orderItemMapper.insert(orderItem);
                 orderItemVO.setItemId(orderItem.getItemId());
@@ -458,6 +464,11 @@ public class OrderService extends BaseService<Order> {
             outboundVO.setFlgHandleSetting(orderVO.getFlgHandleSetting());
             outboundVO.setFromId(order.getOrderId());
             outboundVO.setFromNo(order.getOrderNo());
+            outboundVO.setOutDate(orderVO.getDeliveryDate());
+            outboundVO.setFactAmt(orderVO.getFactAmt());
+            outboundVO.setDiscount(orderVO.getDiscount());
+            outboundVO.setDiscAmt(orderVO.getDiscAmt());
+            outboundVO.setSumAmount(orderVO.getSumAmount());
             outboundSaleOrderService.inventoryOUtBond(outboundVO);
         }