Browse Source

update bug

caifc 3 years ago
parent
commit
c4f1c7ea3c

+ 21 - 1
ruoyi-warehouse/src/main/java/com/ruoyi/approvalFlow/service/impl/AuditPathsServiceImpl.java

@@ -8,6 +8,7 @@ import com.ruoyi.approvalFlow.mapper.*;
 import com.ruoyi.approvalFlow.service.IAuditPathsService;
 import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.core.domain.model.LoginUser;
+import com.ruoyi.common.exception.WarehouseException;
 import com.ruoyi.common.utils.DateUtils;
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.finance.domain.TFee;
@@ -32,6 +33,7 @@ import org.springframework.transaction.annotation.Transactional;
 import org.springframework.transaction.interceptor.TransactionAspectSupport;
 
 import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * 审批流配置主Service业务层处理
@@ -341,7 +343,24 @@ public class AuditPathsServiceImpl implements IAuditPathsService {
                             tWarehouseBillsMapper.warehouseFollowUpdate(auditItems.getBillId(), fettle, at.getAuditItem());
                         }
                         tWarehousebillsfeesMapper.warehouseFeesFollowUpdate(auditItems.getBillId(), fettle, at.getAuditItem());
-                        if (Objects.equals(auditItems.getActId(), 150L)) {
+                        if (Objects.equals(auditItems.getActId(), 120L)) {
+                            List<TWarehousebillsfees> feesList = tWarehousebillsfeesMapper.selectWarehousebillsfeesByPId(auditItems.getBillId());
+                            // 获取仓储费,并判断费用中是否存在仓储费
+                            TFee ccf = tFeeMapper.seletFeeByCode("CCF");
+                            if (Objects.isNull(ccf)) {
+                                throw new WarehouseException("未找到仓储费费用信息");
+                            }
+                            // 过滤出费用类型等于仓储费并且有商机id,并取出来进行更新仓储费计费日期
+                            List<TWarehousebillsfees> warehousebillsfees = feesList.stream().filter(li -> Objects.equals(li.getfFeeid(), ccf.getfId()) && Objects.nonNull(li.getSrcId()))
+                                    .distinct().collect(Collectors.toList());
+                            // 更新子表仓储费截止日期
+                            warehousebillsfees.forEach(li -> {
+                                TWarehousebillsitems warehousebillsitems = new TWarehousebillsitems();
+                                warehousebillsitems.setfId(li.getSrcId());
+                                warehousebillsitems.setfStorageFeeDeadline(li.getfBillingDeadline());
+                                tWarehousebillsitemsMapper.updateById(warehousebillsitems);
+                            });
+                        } else if (Objects.equals(auditItems.getActId(), 150L)) {
                             List<TWarehousebillsfees> feesList = tWarehousebillsfeesMapper.selectWarehousebillsfeesByPId(auditItems.getBillId());
                             if (CollectionUtils.isNotEmpty(feesList)) {
                                 for (TWarehousebillsfees f : feesList) {
@@ -362,6 +381,7 @@ public class AuditPathsServiceImpl implements IAuditPathsService {
                                 }
                             }
                         }
+
                     } else if (auditItems.getActId() >= 210 && auditItems.getActId() <= 230) {
                         // 财务模块
                         if ("T".equals(at.getIffinalItem())) {

+ 3 - 0
ruoyi-warehouse/src/main/java/com/ruoyi/finance/mapper/TFeeMapper.java

@@ -112,6 +112,9 @@ public interface TFeeMapper {
 
     public List<Map<String, Object>> selectDetailedList1(TWarehousebill tWarehousebill);
 
+    // 根据编号查询费用信息
+    public TFee seletFeeByCode(@Param("code") String code);
+
     /**
      * 网页版发票查询
      * @param tFee

+ 14 - 0
ruoyi-warehouse/src/main/java/com/ruoyi/warehouseBusiness/domain/TWarehousebillsfees.java

@@ -288,6 +288,12 @@ public class TWarehousebillsfees extends BaseEntity {
     private String fBusinessType;
 
     /**
+     * 费用信息备注
+     */
+    @Excel(name = "费用信息备注")
+    private String priceDateRemarks;
+
+    /**
      * 查询费用报表时间区间
      */
     private List<String> fBsdateList;
@@ -319,6 +325,14 @@ public class TWarehousebillsfees extends BaseEntity {
         return warehouseName;
     }
 
+    public String getPriceDateRemarks() {
+        return priceDateRemarks;
+    }
+
+    public void setPriceDateRemarks(String priceDateRemarks) {
+        this.priceDateRemarks = priceDateRemarks;
+    }
+
     public void setWarehouseName(String warehouseName) {
         this.warehouseName = warehouseName;
     }

+ 39 - 0
ruoyi-warehouse/src/main/java/com/ruoyi/warehouseBusiness/dto/CalculateStorageFeesDto.java

@@ -0,0 +1,39 @@
+package com.ruoyi.warehouseBusiness.dto;
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.Date;
+
+/**
+ * @author caifc
+ * @date 2021-10-22 9:43
+ */
+@Data
+public class CalculateStorageFeesDto implements Serializable {
+    private static final long serialVersionUID = 1L;
+
+    //出库客户Id
+    private Long fCorpid;
+    //物资类型Id
+    private String fGoodsid;
+    //时长天数(需要计算仓储费的时长)
+    private Long days;
+    //计价单位
+    private Long feeUnitid;
+    //数量
+    private BigDecimal itemNums;
+    //已经计算过仓储费的天数(假设传参80,则阶梯计价时按照80往后的计算)  21.01.14 曹志刚要求新增
+    private Long earlySumDays;
+    //是否需要校验仓库
+    private String cangKey;
+    //仓库id
+    private Long warehouseId;
+    // 货物计算仓储费开始与截止时间  21.10.22 郝臻新需求
+    private Date startTime;
+    private Date endTime;
+
+}

+ 44 - 0
ruoyi-warehouse/src/main/java/com/ruoyi/warehouseBusiness/enums/warehouseActIdEnum.java

@@ -0,0 +1,44 @@
+package com.ruoyi.warehouseBusiness.enums;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+/**
+ * @author caifc
+ * @date 2021-10-22 17:19
+ */
+@Getter
+@AllArgsConstructor
+public enum warehouseActIdEnum {
+
+    //仓库审批活动号
+    INSTOCK(110, "入库"),
+    OUTSTOCK(120, "出库"),
+    FORWARDING(130, "货转"),
+    TRANSFER(140, "调拨"),
+    CALCULATE_COST(150, "计算仓储费"),
+    CLEARANCE(160, "货物通关"),
+
+    //财务审批活动号
+    RECONCILIATION(210, "对账"),
+    TOLL(220, "收费"),
+    PAID(230, "付费"),
+
+    //仓储计划活动号
+    STORAGE_FEE(310, "仓储费"),
+    PLAN_FEE(320, "计划费"),
+
+    //凯和
+    CUSTOMS_APPROVAL1(111, "只有上面主表标星字段"),
+    CUSTOMS_APPROVAL2(121, "只有上面主表标星字段"),
+    CUSTOMS_APPROVAL3(131, "只有上面主表标星字段"),
+    CUSTOMS_APPROVAL4(141, "只有上面主表标星字段"),
+    CUSTOMS_APPROVAL5(151, "只有上面主表标星字段"),
+    CUSTOMS_APPROVAL6(161, "只有上面主表标星字段"),
+
+    ;
+
+    private final Integer actId;
+    private final String name;
+
+}

+ 79 - 44
ruoyi-warehouse/src/main/java/com/ruoyi/warehouseBusiness/service/impl/TWarehouseAgreementServiceImpl.java

@@ -8,7 +8,6 @@ import com.ruoyi.approvalFlow.domain.AuditItems;
 import com.ruoyi.approvalFlow.service.impl.AuditItemsServiceImpl;
 import com.ruoyi.basicData.domain.TCorps;
 import com.ruoyi.basicData.domain.TFees;
-import com.ruoyi.basicData.domain.TGoods;
 import com.ruoyi.basicData.mapper.TCorpsMapper;
 import com.ruoyi.basicData.mapper.TFeesMapper;
 import com.ruoyi.basicData.mapper.TGoodsMapper;
@@ -23,6 +22,7 @@ import com.ruoyi.system.mapper.SysDeptMapper;
 import com.ruoyi.warehouseBusiness.domain.BillnoDel;
 import com.ruoyi.warehouseBusiness.domain.TWarehouseAgreement;
 import com.ruoyi.warehouseBusiness.domain.TWarehouseAgreementitems;
+import com.ruoyi.warehouseBusiness.dto.CalculateStorageFeesDto;
 import com.ruoyi.warehouseBusiness.mapper.BillnoDelMapper;
 import com.ruoyi.warehouseBusiness.mapper.TWarehouseAgreementMapper;
 import com.ruoyi.warehouseBusiness.mapper.TWarehouseAgreementitemsMapper;
@@ -34,7 +34,6 @@ import org.springframework.transaction.interceptor.TransactionAspectSupport;
 
 import java.math.BigDecimal;
 import java.util.*;
-import java.util.stream.Collectors;
 
 /**
  * 仓储费Service业务层处理
@@ -430,78 +429,87 @@ public class TWarehouseAgreementServiceImpl implements ITWarehouseAgreementServi
         }
     }
 
-
     /**
      * 计算存储费用
      *
-     * @param fCorpid      出库客户Id
-     * @param fGoodsid     物资类型Id
-     * @param days         时长天数(需要计算仓储费的时长)
-     * @param feeUnitid    计价单位
-     * @param itemNums     数量
-     * @param earlySumDays 已经计算过仓储费的天数(假设传参80,则阶梯计价时按照80往后的计算)  21.01.14 曹志刚要求新增
-     * @param cangKey      是否需要校验仓库
-     * @param warehouseId  仓库id
-     * @return  结果
+     * @param storageFeesDto 参数
+     * @return 结果
      * @author shanxin
      */
-    public Map<String, Object> getCarryingCost(Long fCorpid,
-                                               String fGoodsid,
-                                               Long days,
-                                               Long feeUnitid,
-                                               BigDecimal itemNums,
-                                               Long earlySumDays,
-                                               String cangKey,
-                                               Long warehouseId) {
+    public Map<String, Object> getCarryingCost(CalculateStorageFeesDto storageFeesDto) {
         Map<String, Object> map = new HashMap<>();
-        if (null == fCorpid ||
-                null == fGoodsid ||
-                null == days ||
-                null == feeUnitid ||
-                null == itemNums ||
-                null == earlySumDays ||
-                null == cangKey) {
+        if (null == storageFeesDto.getFCorpid() ||
+                null == storageFeesDto.getFGoodsid() ||
+                null == storageFeesDto.getDays() ||
+                null == storageFeesDto.getFeeUnitid() ||
+                null == storageFeesDto.getItemNums() ||
+                null == storageFeesDto.getEarlySumDays() ||
+                null == storageFeesDto.getWarehouseId() ||
+                null == storageFeesDto.getStartTime() ||
+                null == storageFeesDto.getEndTime() ||
+                null == storageFeesDto.getCangKey()) {
             return null;
         }
         List<TWarehouseAgreementitems> itemList =
-                this.tWarehouseAgreementitemsMapper.getItemsBytWarehouseAgreementMsg(fCorpid, fGoodsid, feeUnitid, String.valueOf(warehouseId), cangKey);
+                this.tWarehouseAgreementitemsMapper.getItemsBytWarehouseAgreementMsg(storageFeesDto.getFCorpid(), storageFeesDto.getFGoodsid(), storageFeesDto.getFeeUnitid(),
+                        String.valueOf(storageFeesDto.getWarehouseId()), storageFeesDto.getCangKey());
         if (CollUtil.isEmpty(itemList)) {
             return null;
         }
-        BigDecimal money = new BigDecimal(0);
+        BigDecimal money = BigDecimal.ZERO;
         Long dayLength = 0L;
         Long feeId = 0L;
-
+        // 备注  天X钱=金额
         String remark = "";
+        // 计费区间  月日-月日X钱
+        String billingInterval = "";
         for (TWarehouseAgreementitems tWarehouseAgreementitems : itemList) {
-            if (days < 1) break;
-            if (earlySumDays >= tWarehouseAgreementitems.getfEndays())
+            if (storageFeesDto.getDays() < 1) break;
+            if (storageFeesDto.getEarlySumDays() >= tWarehouseAgreementitems.getfEndays())
                 continue; //将已算账的天数 与 计费规则的 最后一天作比较如果 已算10天 > 规则结束  不算帐
-
+            // 计算仓储日期
             dayLength = tWarehouseAgreementitems.getfEndays() - tWarehouseAgreementitems.getfFromdays() + 1L; //阶梯中的结束-开始日期
-            String information = "";
 
-            if (days >= dayLength) {
+            String details;
+            String interval;
+
+            if (storageFeesDto.getDays() >= dayLength) {
                 feeId = tWarehouseAgreementitems.getfFeeid();
-                BigDecimal calculate = this.getCalculate(itemNums, tWarehouseAgreementitems.getfPrice(), dayLength);
+                BigDecimal calculate = this.getCalculate(storageFeesDto.getItemNums(), tWarehouseAgreementitems.getfPrice(), dayLength);
                 money = money.add(calculate);
-                days = days - dayLength;
-                information = dayLength + "天*" + tWarehouseAgreementitems.getfPrice() + "元*" + itemNums + " = " + calculate + "元";
+                storageFeesDto.setDays(storageFeesDto.getDays() - dayLength);
+                // 计算费用明细
+                details = assemblyBillingDetails(dayLength, tWarehouseAgreementitems.getfPrice(), storageFeesDto.getItemNums(), calculate);
+                // 计算区间费用信息
+                interval = assemblyBillingInterval(storageFeesDto.getStartTime(), dayLength.intValue(), tWarehouseAgreementitems.getfPrice());
                 if (StringUtils.isEmpty(remark)) {
-                    remark = information;
+                    remark = details;
+                } else {
+                    remark = remark + "," + details;
+                }
+                if (StringUtils.isEmpty(billingInterval)) {
+                    billingInterval = interval;
                 } else {
-                    remark = remark + "," + information;
+                    billingInterval = billingInterval + "," + interval;
                 }
             } else {
                 feeId = tWarehouseAgreementitems.getfFeeid();
-                BigDecimal calculate = this.getCalculate(itemNums, tWarehouseAgreementitems.getfPrice(), days);
+                BigDecimal calculate = this.getCalculate(storageFeesDto.getItemNums(), tWarehouseAgreementitems.getfPrice(), storageFeesDto.getDays());
                 money = money.add(calculate);
 //                long day = days - tWarehouseAgreementitems.getfFromdays();
-                information = days + "天*" + tWarehouseAgreementitems.getfPrice() + "元*" + itemNums + " = " + calculate + "元";
+                // 计算费用明细
+                details = assemblyBillingDetails(storageFeesDto.getDays(), tWarehouseAgreementitems.getfPrice(), storageFeesDto.getItemNums(), calculate);
+                // 计算区间费用信息
+                interval = assemblyBillingInterval(storageFeesDto.getStartTime(), storageFeesDto.getDays().intValue(), tWarehouseAgreementitems.getfPrice());
                 if (StringUtils.isEmpty(remark)) {
-                    remark = information;
+                    remark = details;
+                } else {
+                    remark = remark + "," + details;
+                }
+                if (StringUtils.isEmpty(billingInterval)) {
+                    billingInterval = interval;
                 } else {
-                    remark = remark + "," + information;
+                    billingInterval = billingInterval + "," + interval;
                 }
                 break;
             }
@@ -509,11 +517,38 @@ public class TWarehouseAgreementServiceImpl implements ITWarehouseAgreementServi
         map.put("amt", money);
         map.put("feeId", feeId);
         map.put("remark", remark);
+        // 计费区间
+        map.put("billingInterval", billingInterval);
         return map;
     }
 
 
     /**
+     * 组装运费明细记录
+     *
+     * @param dayLength 天数
+     * @param price     单价
+     * @param itemNums  数量
+     * @param calculate 金额
+     */
+    private String assemblyBillingDetails(Long dayLength, BigDecimal price, BigDecimal itemNums, BigDecimal calculate) {
+        return dayLength + "天*" + price + "元*" + itemNums + " = " + calculate + "元";
+    }
+
+    /**
+     * 计算计费区间
+     *
+     * @param startTime 开始时间
+     * @param days      推进天数
+     * @param price     单价
+     * @return 计算计费区间
+     */
+    private String assemblyBillingInterval(Date startTime, int days, BigDecimal price) {
+        return DateUtils.dateTime(startTime) + "->" + DateUtils.dateTime(DateUtils.dateAdd(startTime, days)) +
+                "*" + price + "元";
+    }
+
+    /**
      * 数量 * 单价 * 天数
      *
      * @param itemNumsBig 数量

+ 178 - 120
ruoyi-warehouse/src/main/java/com/ruoyi/warehouseBusiness/service/impl/TWarehouseBillsServiceImpl.java

@@ -4,7 +4,9 @@ package com.ruoyi.warehouseBusiness.service.impl;
 import cn.hutool.core.bean.BeanUtil;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.ruoyi.approvalFlow.domain.AuditItems;
 import com.ruoyi.approvalFlow.mapper.AuditItemsMapper;
 import com.ruoyi.approvalFlow.service.impl.AuditItemsServiceImpl;
@@ -28,6 +30,8 @@ import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.common.utils.ip.AddressUtils;
 import com.ruoyi.common.utils.poi.ExcelUtils;
 import com.ruoyi.finance.WarehouseType;
+import com.ruoyi.finance.domain.TFee;
+import com.ruoyi.finance.mapper.TFeeMapper;
 import com.ruoyi.quotation.domain.TSeaprice;
 import com.ruoyi.quotation.mapper.TSeapriceMapper;
 import com.ruoyi.reportManagement.domain.TWareHouseItemsExcel;
@@ -44,6 +48,7 @@ import com.ruoyi.system.mapper.*;
 import com.ruoyi.system.service.ISysConfigService;
 import com.ruoyi.system.service.impl.SysConfigServiceImpl;
 import com.ruoyi.warehouseBusiness.domain.*;
+import com.ruoyi.warehouseBusiness.dto.CalculateStorageFeesDto;
 import com.ruoyi.warehouseBusiness.excel.*;
 import com.ruoyi.warehouseBusiness.mapper.*;
 import com.ruoyi.warehouseBusiness.service.ITWarehouseBillsService;
@@ -64,6 +69,7 @@ import org.springframework.web.multipart.MultipartFile;
 
 import java.io.*;
 import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.*;
@@ -83,6 +89,9 @@ import static java.util.stream.Collectors.toList;
 public class TWarehouseBillsServiceImpl implements ITWarehouseBillsService {
 
     @Autowired
+    private TFeeMapper tFeeMapper;
+
+    @Autowired
     private TFeesMapper tFeesMapper;
 
     @Autowired
@@ -3982,20 +3991,24 @@ public class TWarehouseBillsServiceImpl implements ITWarehouseBillsService {
         List<SysDictData> taxRate = sysDictDataMapper.selectDictDataByType("tax_rate");
         for (Map<String, Object> item : mapItem) {
             if (StringUtils.isNull(item.get("fBillingway"))) {
-                map.put("error", "单号:" + item.get("fBillno") + ",业务日期:" + item.get("fBsdate") + "未找到库存总账的计费单位,请确认");
-                return map;
+                throw new WarehouseException("单号:" + item.get("fBillno") + ",业务日期:" + item.get("fBsdate") + "未找到库存总账的计费单位,请确认");
             }
+            CalculateStorageFeesDto storageFeesDto = new CalculateStorageFeesDto();
+            storageFeesDto.setFCorpid(warehouseBills.getfCorpid());
+            storageFeesDto.setCangKey(cangKey);
+            storageFeesDto.setWarehouseId(Long.parseLong(String.valueOf(item.get("warehouse"))));
+
             Date fBsdate = (Date) item.get("fBsdate");
-            long fCorpid = warehouseBills.getfCorpid();
             String fBilltype = (String) item.get("fBilltype");
-            Long warehouseId = Long.parseLong(String.valueOf(item.get("warehouse")));
             String fGoodsid = (String) item.get("fTypeid");
             if (StringUtils.isNotEmpty(fGoodsid)) {
                 fGoodsid = "\"" + fGoodsid + "\"";
             }
-            long fId = Long.valueOf(String.valueOf(item.get("fId"))).longValue();
+            storageFeesDto.setFGoodsid(fGoodsid);
+
+            long fId = Long.valueOf(String.valueOf(item.get("fId")));
             // 累计计费天数
-            long accumulatedDays = DateUtils.getDateDay((Date) item.get("fChargedate"), (Date) item.get("fOriginalbilldate"));
+            storageFeesDto.setEarlySumDays(DateUtils.getDateDay((Date) item.get("fChargedate"), (Date) item.get("fOriginalbilldate")));
             // 库存天数
             long fInventoryDays = 0L;
             // 要计费天数
@@ -4003,38 +4016,45 @@ public class TWarehouseBillsServiceImpl implements ITWarehouseBillsService {
             if ("SJCK".equals(fBilltype)) {
                 fInventoryDays = DateUtils.getDateDay(fBsdate, (Date) item.get("fOriginalbilldate"));
                 fBillingDays = fInventoryDays;
+                storageFeesDto.setStartTime((Date) item.get("fOriginalbilldate"));
+                storageFeesDto.setEndTime(fBsdate);
             } else if ("HQZY".equals(fBilltype)) {
                 fInventoryDays = DateUtils.getDateDay(warehouseBills.getfBillingDeadline(), fBsdate);
+                storageFeesDto.setStartTime(fBsdate);
+                storageFeesDto.setEndTime(warehouseBills.getfBillingDeadline());
             } else {
-                fBillingDays = DateUtils.getDateDay(warehouseBills.getfBillingDeadline(), (Date) item.get("fChargedate"));
+                storageFeesDto.setStartTime((Date) item.get("fOriginalbilldate"));
+                storageFeesDto.setEndTime(warehouseBills.getfBillingDeadline());
                 fInventoryDays = DateUtils.getDateDay(warehouseBills.getfBillingDeadline(), (Date) item.get("fOriginalbilldate"));
+                fBillingDays = DateUtils.getDateDay(warehouseBills.getfBillingDeadline(), (Date) item.get("fChargedate"));
             }
+            storageFeesDto.setDays(fBillingDays);
             /*if ("KCZZ".equals(fBilltype)) {
             } else {
                 fInventoryDays = Long.valueOf(String.valueOf(item.get("fBillingDays")));
             }*/
-            Long dictLabel = Long.valueOf(String.valueOf(item.get("fBillingway")));
-            BigDecimal fQty = acquiredQuantity(item, dictLabel);
-            if (fQty.equals(BigDecimal.ZERO)) {
-                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
-                return AjaxResult.error("单号:" + item.get("fBillno") + ",业务日期:" + item.get("fBsdate") + "未找到计费单位,请确认");
+            storageFeesDto.setFeeUnitid(Long.valueOf(String.valueOf(item.get("fBillingway"))));
+            BigDecimal fQty = acquiredQuantity(item, storageFeesDto.getFeeUnitid());
+            if (fQty.compareTo(BigDecimal.ZERO) == 0) {
+                continue;
             }
+            storageFeesDto.setItemNums(fQty);
             // 仓储费协议计算
-            Map<String, Object> objectMap = tWarehouseAgreementService.getCarryingCost(fCorpid, fGoodsid, fBillingDays, dictLabel, fQty, accumulatedDays, cangKey, warehouseId);
+            Map<String, Object> objectMap = tWarehouseAgreementService.getCarryingCost(storageFeesDto);
             if (StringUtils.isNull(objectMap)) {
-                map.put("error", "单号:" + item.get("fBillno") + ",业务日期:" + item.get("fBsdate") + "未找到仓储费协议,请确认");
-                return map;
+                throw new WarehouseException("单号:" + item.get("fBillno") + ",业务日期:" + item.get("fBsdate") + "未找到仓储费协议,请确认");
             }
             String mblno = "";
             if (StringUtils.isNotNull(item.get("fMblno"))) {
                 mblno = item.get("fMblno").toString();
             }
             String remark = objectMap.get("remark").toString();
+            String billingInterval = objectMap.get("billingInterval").toString();
             feeId = Long.parseLong(String.valueOf(objectMap.get("feeId")));
             BigDecimal amt = (BigDecimal) objectMap.get("amt");
             map.put("feeId", feeId);
             map.put("itemFeeId", objectMap.get("feeId"));
-            sumAmt = sumAmt.add(amt).setScale(2, BigDecimal.ROUND_HALF_UP);
+            sumAmt = sumAmt.add(amt).setScale(2, RoundingMode.HALF_UP);
             TWarehousebillsfees fees = new TWarehousebillsfees();
             fees.setfFeeid(feeId);
             fees.setfDc("D");
@@ -4051,13 +4071,14 @@ public class TWarehouseBillsServiceImpl implements ITWarehouseBillsService {
             fees.setfUnitprice(sumAmt);
             fees.setfBilltype(fBilltype);
             fees.setCreateTime(new Date());
-            fees.setfWarehouseid(warehouseId);
+            fees.setfWarehouseid(storageFeesDto.getWarehouseId());
             fees.setfBillingDays(fBillingDays);
             fees.setfQty(new BigDecimal(1));
             fees.setfPid(warehouseBills.getfId());
             fees.setfInventoryDays(fInventoryDays);
             fees.setfExrate(new BigDecimal(1));
             fees.setfCorpid(warehouseBills.getfCorpid());
+            fees.setPriceDateRemarks(billingInterval);
             fees.setfMarks(item.get("fMarks").toString());
             fees.setSrcBillNo((String) item.get("fBillno"));
             fees.setfChargedate((Date) item.get("fChargedate"));
@@ -4080,6 +4101,99 @@ public class TWarehouseBillsServiceImpl implements ITWarehouseBillsService {
     }
 
     /**
+     * 新增库存费计算
+     *
+     * @param tWarehouseBills 主表的查询条件
+     * @param loginUser       登录用户
+     * @param billsType       状态
+     * @return 结果
+     */
+    @Override
+    @Transactional
+    public AjaxResult calculateStorageFees(TWarehouseBills tWarehouseBills, LoginUser loginUser, String billsType) {
+        if (StringUtils.isNull(tWarehouseBills.getfCorpid())) {
+            return AjaxResult.error("请选择客户信息");
+        }
+        long fPid = 0L;
+        if (StringUtils.isNull(tWarehouseBills.getfId())) {
+            // 生成流水号
+            Date time = new Date();
+            String billNo = billnoSerialServiceImpl.getSerialNumber("JSCCF", time);
+            tWarehouseBills.setfBillno(billNo);
+            if (StringUtils.isNull(tWarehouseBills.getfBillstatus())) {
+                tWarehouseBills.setfBillstatus(2L);
+            }
+            tWarehouseBills.setfBilltype(billsType);
+            tWarehouseBills.setfBsdeptid(loginUser.getUser().getDeptId());
+            tWarehouseBills.setCreateBy(loginUser.getUser().getUserName());
+            tWarehouseBills.setCreateTime(new Date());
+            tWarehouseBillsMapper.insertTWarehousebills(tWarehouseBills);
+            fPid = tWarehouseBills.getfId();
+        } else {
+            tWarehousebillsfeesMapper.deleteByFPid(tWarehouseBills.getfId());
+            tWarehousebillsitemsMapper.deleteByFPid(tWarehouseBills.getfId());
+            tWarehouseBills.setUpdateBy(loginUser.getUser().getUserName());
+            tWarehouseBills.setUpdateTime(new Date());
+            tWarehouseBillsMapper.updateTWarehousebills(tWarehouseBills);
+            fPid = tWarehouseBills.getfId();
+        }
+        // 计划物资明细
+        List<TWarehousebillsfees> itemsList = new ArrayList<>();
+        Map<String, Object> map = new HashMap<>();
+        //调一次公共方法,获取字符类型的true或者false传
+        String cangKey = sysConfigServiceImpl.selectConfigByKey("agreement.warehouse");
+        // 库存总账id
+        long whgenlegFeeId = 0;
+        // 计费单位
+        long feeUnitid = 1;
+        // 查出所有仓库 给后续匹配仓库名字使用
+        List<TWarehouse> warehouseList = tWarehouseMapper.selectTWarehouseList(new TWarehouse());
+        // 查询 出库 货转的库存明细
+        List<Map<String, Object>> warehousebillsitemsList = tWarehousebillsitemsMapper.selectStorageFeeItemList(tWarehouseBills);
+        if (warehousebillsitemsList.size() != 0) {
+            Map<String, Object> mapItem = getWarehouseItems(tWarehouseBills, warehousebillsitemsList, loginUser, cangKey);
+            if (mapItem.containsKey("error")) {
+                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+                return AjaxResult.error((String) mapItem.get("error"));
+            }
+            itemsList = (List<TWarehousebillsfees>) mapItem.get("itemsList");
+            // 给仓库信息赋值
+            itemsList.forEach(li -> {
+                TWarehouse tWarehouse = warehouseList.stream().filter(warehouse -> Objects.equals(warehouse.getfId(), li.getfWarehouseid()))
+                        .findFirst().orElseThrow(() -> new WarehouseException("找不到仓库信息"));
+                li.setWarehouseName(tWarehouse.getfName());
+            });
+        }
+        List<Map<String, Object>> tWhgenlegs = tWhgenlegMapper.selectStorageFeeItemList(tWarehouseBills);
+        if (CollectionUtils.isNotEmpty(tWhgenlegs)) {
+            Map<String, Object> mapItem = getWarehouseItems(tWarehouseBills, tWhgenlegs, loginUser, cangKey);
+            if (mapItem.containsKey("error")) {
+                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+                return AjaxResult.error((String) mapItem.get("error"));
+            }
+            List<TWarehousebillsfees> itemList = (List<TWarehousebillsfees>) mapItem.get("itemsList");
+            // 给仓库信息赋值
+            for (TWarehousebillsfees li : itemList) {
+                TWarehouse tWarehouse = warehouseList.stream().filter(warehouse -> Objects.equals(warehouse.getfId(), li.getfWarehouseid()))
+                        .findFirst().orElseThrow(() -> new WarehouseException("找不到仓库信息"));
+                li.setWarehouseName(tWarehouse.getfName());
+                itemsList.add(li);
+            }
+        }
+        TFees tFees = new TFees();
+        tFees.setfStatus("2");
+        tFees.setDelFlag("0");
+        List<TFees> feesList = tFeesMapper.selectTFeesList(tFees);
+        if (CollectionUtils.isEmpty(itemsList)) {
+            throw new WarehouseException("未找到合适的库存明细");
+        }
+        map.put("feesList", feesList);
+        map.put("warehouseBills", tWarehouseBills);
+        map.put("warehouseItemList", itemsList);
+        return AjaxResult.success(map);
+    }
+
+    /**
      * 批量生成计算仓储费信息
      *
      * @param warehouseBills
@@ -4098,17 +4212,20 @@ public class TWarehouseBillsServiceImpl implements ITWarehouseBillsService {
                 map.put("error", "单号:" + item.get("fBillno") + ",业务日期:" + item.get("fBsdate") + "未找到库存总账的计费单位,请确认");
                 return map;
             }
+            CalculateStorageFeesDto storageFeesDto = new CalculateStorageFeesDto();
+            storageFeesDto.setFCorpid(warehouseBills.getfCorpid());
+            storageFeesDto.setCangKey(warehouse);
+            storageFeesDto.setWarehouseId(Long.parseLong(String.valueOf(item.get("warehouse"))));
             Date fBsdate = (Date) item.get("fBsdate");
-            long fCorpid = warehouseBills.getfCorpid();
             String fBilltype = (String) item.get("fBilltype");
             String fGoodsid = (String) item.get("fTypeid");
-            Long warehouseId = Long.parseLong(String.valueOf(item.get("warehouse")));
             if (StringUtils.isNotEmpty(fGoodsid)) {
                 fGoodsid = "\"" + fGoodsid + "\"";
             }
-            long fId = Long.valueOf(String.valueOf(item.get("fId"))).longValue();
+            storageFeesDto.setFGoodsid(fGoodsid);
+            long fId = Long.valueOf(String.valueOf(item.get("fId")));
             // 累计计费天数
-            long accumulatedDays = DateUtils.getDateDay((Date) item.get("fChargedate"), (Date) item.get("fOriginalbilldate"));
+            storageFeesDto.setEarlySumDays(DateUtils.getDateDay((Date) item.get("fChargedate"), (Date) item.get("fOriginalbilldate")));
             // 库存天数
             long fInventoryDays = 0L;
             // 要计费天数
@@ -4116,24 +4233,32 @@ public class TWarehouseBillsServiceImpl implements ITWarehouseBillsService {
             if ("SJCK".equals(fBilltype)) {
                 fInventoryDays = DateUtils.getDateDay(fBsdate, (Date) item.get("fChargedate"));
                 fBillingDays = fInventoryDays;
+                storageFeesDto.setStartTime((Date) item.get("fChargedate"));
+                storageFeesDto.setEndTime(fBsdate);
             } else if ("HQZY".equals(fBilltype)) {
                 fInventoryDays = DateUtils.getDateDay(warehouseBills.getfBillingDeadline(), fBsdate);
+                storageFeesDto.setStartTime(fBsdate);
+                storageFeesDto.setEndTime(warehouseBills.getfBillingDeadline());
             } else {
+                storageFeesDto.setStartTime((Date) item.get("fOriginalbilldate"));
+                storageFeesDto.setEndTime(warehouseBills.getfBillingDeadline());
                 fBillingDays = DateUtils.getDateDay(warehouseBills.getfBillingDeadline(), (Date) item.get("fChargedate"));
                 fInventoryDays = DateUtils.getDateDay(warehouseBills.getfBillingDeadline(), (Date) item.get("fOriginalbilldate"));
             }
+            storageFeesDto.setDays(fBillingDays);
             /*if ("KCZZ".equals(fBilltype)) {
             } else {
                 fInventoryDays = Long.valueOf(String.valueOf(item.get("fBillingDays")));
             }*/
-            Long dictLabel = Long.valueOf(String.valueOf(item.get("fBillingway")));
-            BigDecimal fQty = acquiredQuantity(item, dictLabel);
+            storageFeesDto.setFeeUnitid(Long.valueOf(String.valueOf(item.get("fBillingway"))));
+            BigDecimal fQty = acquiredQuantity(item, storageFeesDto.getFeeUnitid());
             if (fQty.equals(BigDecimal.ZERO)) {
                 TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                 return AjaxResult.error("单号:" + item.get("fBillno") + ",业务日期:" + item.get("fBsdate") + "未找到计费单位,请确认");
             }
+            storageFeesDto.setItemNums(fQty);
             // 计算仓储费明细
-            Map<String, Object> objectMap = tWarehouseAgreementService.getCarryingCost(fCorpid, fGoodsid, fBillingDays, dictLabel, fQty, accumulatedDays, warehouse, warehouseId);
+            Map<String, Object> objectMap = tWarehouseAgreementService.getCarryingCost(storageFeesDto);
             if (StringUtils.isNull(objectMap)) {
                 map.put("error", "单号:" + item.get("fBillno") + ",业务日期:" + item.get("fBsdate") + "未找到仓储费协议,请确认");
                 return map;
@@ -4165,7 +4290,7 @@ public class TWarehouseBillsServiceImpl implements ITWarehouseBillsService {
             fees.setfBilltype(fBilltype);
             fees.setfBillingDays(fBillingDays);
             fees.setCreateTime(new Date());
-            fees.setfWarehouseid(warehouseId);
+            fees.setfWarehouseid(storageFeesDto.getWarehouseId());
             fees.setfQty(new BigDecimal(1));
             fees.setfPid(warehouseBills.getfId());
             fees.setfInventoryDays(fInventoryDays);
@@ -4196,99 +4321,6 @@ public class TWarehouseBillsServiceImpl implements ITWarehouseBillsService {
         return map;
     }
 
-    /**
-     * 新增库存费计算
-     *
-     * @param tWarehouseBills 主表的查询条件
-     * @param loginUser       登录用户
-     * @param billsType       状态
-     * @return 结果
-     */
-    @Override
-    @Transactional
-    public AjaxResult calculateStorageFees(TWarehouseBills tWarehouseBills, LoginUser loginUser, String billsType) {
-        if (StringUtils.isNull(tWarehouseBills.getfCorpid())) {
-            return AjaxResult.error("请选择客户信息");
-        }
-        long fPid = 0L;
-        if (StringUtils.isNull(tWarehouseBills.getfId())) {
-            // 生成流水号
-            Date time = new Date();
-            String billNo = billnoSerialServiceImpl.getSerialNumber("JSCCF", time);
-            tWarehouseBills.setfBillno(billNo);
-            if (StringUtils.isNull(tWarehouseBills.getfBillstatus())) {
-                tWarehouseBills.setfBillstatus(2L);
-            }
-            tWarehouseBills.setfBilltype(billsType);
-            tWarehouseBills.setfBsdeptid(loginUser.getUser().getDeptId());
-            tWarehouseBills.setCreateBy(loginUser.getUser().getUserName());
-            tWarehouseBills.setCreateTime(new Date());
-            tWarehouseBillsMapper.insertTWarehousebills(tWarehouseBills);
-            fPid = tWarehouseBills.getfId();
-        } else {
-            tWarehousebillsfeesMapper.deleteByFPid(tWarehouseBills.getfId());
-            tWarehousebillsitemsMapper.deleteByFPid(tWarehouseBills.getfId());
-            tWarehouseBills.setUpdateBy(loginUser.getUser().getUserName());
-            tWarehouseBills.setUpdateTime(new Date());
-            tWarehouseBillsMapper.updateTWarehousebills(tWarehouseBills);
-            fPid = tWarehouseBills.getfId();
-        }
-        // 计划物资明细
-        List<TWarehousebillsfees> itemsList = new ArrayList<>();
-        Map<String, Object> map = new HashMap<>();
-        //调一次公共方法,获取字符类型的true或者false传
-        String cangKey = sysConfigServiceImpl.selectConfigByKey("agreement.warehouse");
-        // 库存总账id
-        long whgenlegFeeId = 0;
-        // 计费单位
-        long feeUnitid = 1;
-        // 查出所有仓库 给后续匹配仓库名字使用
-        List<TWarehouse> warehouseList = tWarehouseMapper.selectTWarehouseList(new TWarehouse());
-        // 查询 出库 货转的库存明细
-        List<Map<String, Object>> warehousebillsitemsList = tWarehousebillsitemsMapper.selectStorageFeeItemList(tWarehouseBills);
-        if (warehousebillsitemsList.size() != 0) {
-            Map<String, Object> mapItem = getWarehouseItems(tWarehouseBills, warehousebillsitemsList, loginUser, cangKey);
-            if (mapItem.containsKey("error")) {
-                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
-                return AjaxResult.error((String) mapItem.get("error"));
-            }
-            itemsList = (List<TWarehousebillsfees>) mapItem.get("itemsList");
-            // 给仓库信息赋值
-            itemsList.forEach(li -> {
-                TWarehouse tWarehouse = warehouseList.stream().filter(warehouse -> Objects.equals(warehouse.getfId(), li.getfWarehouseid()))
-                        .findFirst().orElseThrow(() -> new WarehouseException("找不到仓库信息"));
-                li.setWarehouseName(tWarehouse.getfName());
-            });
-        }
-        List<Map<String, Object>> tWhgenlegs = tWhgenlegMapper.selectStorageFeeItemList(tWarehouseBills);
-        if (tWhgenlegs.size() != 0) {
-            Map<String, Object> mapItem = getWarehouseItems(tWarehouseBills, tWhgenlegs, loginUser, cangKey);
-            if (mapItem.containsKey("error")) {
-                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
-                return AjaxResult.error((String) mapItem.get("error"));
-            }
-            List<TWarehousebillsfees> itemList = (List<TWarehousebillsfees>) mapItem.get("itemsList");
-            // 给仓库信息赋值
-            for (TWarehousebillsfees li : itemList) {
-                TWarehouse tWarehouse = warehouseList.stream().filter(warehouse -> Objects.equals(warehouse.getfId(), li.getfWarehouseid()))
-                        .findFirst().orElseThrow(() -> new WarehouseException("找不到仓库信息"));
-                li.setWarehouseName(tWarehouse.getfName());
-                itemsList.add(li);
-            }
-        }
-        TFees tFees = new TFees();
-        tFees.setfStatus("2");
-        tFees.setDelFlag("0");
-        List<TFees> feesList = tFeesMapper.selectTFeesList(tFees);
-        if (itemsList.size() <= 0) {
-            return AjaxResult.error("未找到合适的库存明细");
-        }
-        map.put("feesList", feesList);
-        map.put("warehouseBills", tWarehouseBills);
-        map.put("warehouseItemList", itemsList);
-        return AjaxResult.success(map);
-    }
-
     @Override
     @Transactional
     public AjaxResult calculateStorageFeesList(List<TWarehouseBills> tWarehouseBillsList, LoginUser loginUser, String billsType) {
@@ -4858,7 +4890,10 @@ public class TWarehouseBillsServiceImpl implements ITWarehouseBillsService {
         tWarehousebills.setfNetweight(itemInFo.getfNetweight());
         tWarehousebills.setfGrossweight(itemInFo.getfGrossweight());
         tWarehousebillsfeesMapper.warehouseFeesFollowUpdate(tWarehousebills.getfId(), 2L, new Date());
-        if ("JSCCF".equals(tWarehousebills.getfBilltype())) {
+        // 判断是否出库
+        if (tWarehousebills.getfBilltype().equals(WarehouseType.SJCK.getType())) {
+            cancellationInStockFee(tWarehousebills);
+        } else if ("JSCCF".equals(tWarehousebills.getfBilltype())) {
             List<TWarehousebillsfees> feesList = tWarehousebillsfeesMapper.selectWarehousebillsfeesByPId(fId);
             // 取出本次变更的日期
             Date chargedate = DateUtils.dateAdd(tWarehousebills.getfBillingDeadline(), 1);
@@ -4876,7 +4911,6 @@ public class TWarehouseBillsServiceImpl implements ITWarehouseBillsService {
             if (!forwardingIds.isEmpty() && tWarehousebillsitemsMapper.queryChangedByFchargedate(forwardingIds, chargedate) > 0) {
                 throw new WarehouseException("审批撤销失败,货转明细存在二级计算");
             }
-
             for (TWarehousebillsfees wareItem : feesList) {
                 if (StringUtils.isNull(wareItem.getSrcId())) {
                     continue;
@@ -4909,6 +4943,30 @@ public class TWarehouseBillsServiceImpl implements ITWarehouseBillsService {
     }
 
     /**
+     * 撤销入库费用信息,并更新子订单
+     *
+     * @param tWarehousebills 订单信息
+     */
+    private void cancellationInStockFee(TWarehouseBills tWarehousebills) {
+        LambdaUpdateWrapper<TWarehousebillsitems> updateWrapper = Wrappers.<TWarehousebillsitems>lambdaUpdate();
+        // 查询出库费用信息
+        List<TWarehousebillsfees> feesList = tWarehousebillsfeesMapper.selectWarehousebillsfeesByPId(tWarehousebills.getfId());
+        // 获取仓储费,并判断费用中是否存在仓储费
+        TFee ccf = tFeeMapper.seletFeeByCode("CCF");
+        if (Objects.isNull(ccf)) {
+            throw new WarehouseException("未找到仓储费费用信息");
+        }
+        // 过滤出费用类型等于仓储费并且有商机id,并取出来进行更新仓储费计费日期
+        List<Long> itemIds = feesList.stream().filter(li -> Objects.equals(li.getfFeeid(), ccf.getfId()) && Objects.nonNull(li.getSrcId()))
+                .map(TWarehousebillsfees::getSrcId).distinct().collect(toList());
+
+        updateWrapper = updateWrapper.in(TWarehousebillsitems::getfPid, itemIds)
+                .isNull(TWarehousebillsitems::getfStorageFeeDeadline);
+
+        tWarehousebillsitemsMapper.update(new TWarehousebillsitems(), updateWrapper);
+    }
+
+    /**
      * 撤销已审核通过的接单入库信息
      *
      * @param fId

+ 6 - 0
ruoyi-warehouse/src/main/resources/mapper/finance/TFeeMapper.xml

@@ -1809,4 +1809,10 @@
         <if test="fBillstatus != null and fBillstatus != '' and fBillstatus != 'null' ">and tf.f_billstatus = #{fBillstatus}</if>
         ORDER BY tf.f_id desc
     </select>
+
+    <select id="seletFeeByCode" resultType="com.ruoyi.finance.domain.TFee">
+        <include refid="selectTFeeVo"/>
+        where f_no = #{code} and del_flag = 0
+    </select>
+
 </mapper>

+ 7 - 1
ruoyi-warehouse/src/main/resources/mapper/warehouseBusiness/TWarehousebillsfeesMapper.xml

@@ -51,6 +51,7 @@
         <result property="fBilltype" column="f_billtype"/>
         <result property="fBillingway" column="f_billingway"/>
         <result property="fBsdate" column="f_bsdate"/>
+        <result property="priceDateRemarks" column="price_date_remarks"/>
         <result property="fOriginalbilldate" column="f_originalbilldate"/>
         <result property="fStltypeid" column="f_stltypeid"/>
         <result property="fBusinessType" column="f_business_type"/>
@@ -107,7 +108,8 @@
                f_originalbilldate,
                f_stltypeid,
                f_business_type,
-               f_src_type_id
+               f_src_type_id,
+               price_date_remarks
         from t_warehousebillsfees
     </sql>
 
@@ -315,6 +317,7 @@
             <if test="fStltypeid != null">f_stltypeid,</if>
             <if test="fBusinessType != null">f_business_type,</if>
             <if test="fSrcTypeId != null">f_src_type_id,</if>
+            <if test="priceDateRemarks != null">price_date_remarks,</if>
         </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="fPid != null">#{fPid},</if>
@@ -366,6 +369,7 @@
             <if test="fStltypeid != null">#{fStltypeid},</if>
             <if test="fBusinessType != null">#{fBusinessType},</if>
             <if test="fSrcTypeId != null">#{fSrcTypeId},</if>
+            <if test="priceDateRemarks != null">#{priceDateRemarks},</if>
         </trim>
     </insert>
 
@@ -419,6 +423,7 @@
             <if test="fBsdate != null">f_bsdate = #{fBsdate},</if>
             <if test="fOriginalbilldate != null">f_originalbilldate = #{fOriginalbilldate},</if>
             <if test="fStltypeid != null">f_stltypeid = #{fStltypeid},</if>
+            <if test="priceDateRemarks != null">price_date_remarks = #{priceDateRemarks},</if>
             <if test="fSrcTypeId != null">f_src_type_id = #{fSrcTypeId},</if>
         </trim>
         where f_id = #{fId}
@@ -569,6 +574,7 @@
         tw.f_mblno,
         tw.f_product_name,
         tw.f_marks,
+        tw.price_date_remarks,
         tw.f_chargedate,
         tw.f_billing_deadline,
         tw.f_inventory_days,