Browse Source

解决计算仓储费BUG

Sun 3 years ago
parent
commit
e081747969

+ 31 - 29
ruoyi-warehouse/src/main/java/com/ruoyi/warehouseBusiness/service/impl/TWarehouseAgreementServiceImpl.java

@@ -544,54 +544,58 @@ public class TWarehouseAgreementServiceImpl implements ITWarehouseAgreementServi
         String remark = "";
         // 计费区间  月日-月日X钱
         String billingInterval = "";
+        // 已计费天数
+        Long earlySumDays = storageFeesDto.getEarlySumDays();
+        // 计费天数
+        Long days = storageFeesDto.getDays();
+
         for (TWarehouseAgreementitems tWarehouseAgreementitems : itemList) {
+            feeId = tWarehouseAgreementitems.getfFeeid();
             // 如果要计费天数不足一天,不予计算
-            if (storageFeesDto.getDays() < 1) {
+            if (days < 1) {
                 break;
             }
+
             dayLength = tWarehouseAgreementitems.getfEndays() - tWarehouseAgreementitems.getfFromdays() + 1L;
             // 如果已计费天数超出本阶层,则进入下一层规则,并剪掉当前层天数
-            if (storageFeesDto.getEarlySumDays() >= dayLength) {
-                storageFeesDto.setEarlySumDays(storageFeesDto.getEarlySumDays() - dayLength);
-                continue; //将已算账的天数 与 计费规则的 最后一天作比较如果 已算10天 > 规则结束  不算帐
+            if (earlySumDays >= dayLength) {
+                earlySumDays -= dayLength;
+                continue;
             }
-            // 如果计费日期超过本层天数
-            if (storageFeesDto.getDays() >= dayLength) {
-                // 天数剪掉 剩余已计费库存天数
-                dayLength -= storageFeesDto.getEarlySumDays();
-                storageFeesDto.setEarlySumDays(0L);
-                feeId = tWarehouseAgreementitems.getfFeeid();
-                // 获取最终金额:数量 * 单价 * 天数
-                BigDecimal calculate = this.getCalculate(qty, tWarehouseAgreementitems.getfPrice(), dayLength);
-                money = money.add(calculate);
 
-                storageFeesDto.setDays(storageFeesDto.getDays() - dayLength);
+            if (earlySumDays + days > dayLength) {
+                // 当前层需要计算的天数
+                Long tempDays = dayLength - earlySumDays;
+                earlySumDays = 0L;
+                days -= tempDays;
+                // 计算最终金额:数量 * 单价 * 天数
+                BigDecimal calculate = this.getCalculate(qty, tWarehouseAgreementitems.getfPrice(), tempDays);
+                money = money.add(calculate);
                 // 组装运费明细记录
                 String details = assemblyBillingDetails(StorageFeeRangeDTO.builder()
-                        .dayNum(dayLength).price(tWarehouseAgreementitems.getfPrice()).qty(qty).amt(calculate)
+                        .dayNum(tempDays).price(tWarehouseAgreementitems.getfPrice()).qty(qty).amt(calculate)
                         .build());
                 remark = StringUtils.isEmpty(remark) ? details : remark + "," + details;
-                // 计算区间费用信息
-                String costRange = assemblyBillingInterval(StorageFeeRangeDTO.builder()
-                        .startTime(storageFeesDto.getStartTime()).dayNum(dayLength).price(tWarehouseAgreementitems.getfPrice())
+                // 计算区间费用信息
+                String interval = assemblyBillingInterval(StorageFeeRangeDTO.builder()
+                        .startTime(storageFeesDto.getStartTime()).dayNum(tempDays).price(tWarehouseAgreementitems.getfPrice())
                         .qty(qty).unit(agreementitems.getfFeeunitid())
                         .build());
-                billingInterval = StringUtils.isEmpty(billingInterval) ? costRange : billingInterval + "," + costRange;
+                billingInterval = StringUtils.isEmpty(billingInterval) ? interval : billingInterval + "," + interval;
 
-                storageFeesDto.setStartTime(DateUtils.dateAdd(storageFeesDto.getStartTime(), dayLength.intValue()));
+                // 下一个区间的开始时间调整
+                storageFeesDto.setStartTime(DateUtils.dateAdd(storageFeesDto.getStartTime(), tempDays.intValue()));
             } else {
-                // 最后一次计算天数
-                feeId = tWarehouseAgreementitems.getfFeeid();
-                BigDecimal calculate = this.getCalculate(qty, tWarehouseAgreementitems.getfPrice(), storageFeesDto.getDays());
+                BigDecimal calculate = this.getCalculate(qty, tWarehouseAgreementitems.getfPrice(), days);
                 money = money.add(calculate);
                 // 计算费用明细
                 String details = assemblyBillingDetails(StorageFeeRangeDTO.builder()
-                        .dayNum(storageFeesDto.getDays()).price(tWarehouseAgreementitems.getfPrice()).qty(qty).amt(calculate)
+                        .dayNum(days).price(tWarehouseAgreementitems.getfPrice()).qty(qty).amt(calculate)
                         .build());
                 remark = StringUtils.isEmpty(remark) ? details : remark + "," + details;
-                // 计算区间费用信息
+                // 计算区间费用信息
                 String interval = assemblyBillingInterval(StorageFeeRangeDTO.builder()
-                        .startTime(storageFeesDto.getStartTime()).dayNum(storageFeesDto.getDays())
+                        .startTime(storageFeesDto.getStartTime()).dayNum(days)
                         .price(tWarehouseAgreementitems.getfPrice())
                         .qty(qty).unit(agreementitems.getfFeeunitid())
                         .build());
@@ -668,10 +672,8 @@ public class TWarehouseAgreementServiceImpl implements ITWarehouseAgreementServi
      * @return
      */
     public BigDecimal getCalculate(BigDecimal itemNumsBig, BigDecimal unitPrice, Long dateLength) {
-        BigDecimal money;
         BigDecimal bigDaysBig = new BigDecimal(dateLength);
-        money = itemNumsBig.multiply(unitPrice).multiply(bigDaysBig);
-        return money;
+        return itemNumsBig.multiply(unitPrice).multiply(bigDaysBig);
     }
 
     /**

+ 11 - 12
ruoyi-warehouse/src/main/java/com/ruoyi/warehouseBusiness/service/impl/TWarehouseBillsServiceImpl.java

@@ -4067,17 +4067,17 @@ public class TWarehouseBillsServiceImpl implements ITWarehouseBillsService {
             if (WarehouseTypeEnum.SJCK.getType().equals(item.getFBilltype())) {
                 // 出库在库天数:业务日期-计费日期
                 // 出库计费天数:出库在库天数
-                fInventoryDays = DateUtils.getDateDay(item.getFBsdate(), item.getFChargedate());
-                fBillingDays = fInventoryDays;
-                storageFeesDto.setStartTime(item.getFOriginalbilldate());
+                fInventoryDays = DateUtils.getDateDay(item.getFBsdate(), item.getFOriginalbilldate());
+                fBillingDays = DateUtils.getDateDay(item.getFBsdate(), item.getFChargedate());
+                storageFeesDto.setStartTime(item.getFChargedate());
                 storageFeesDto.setEndTime(item.getFBsdate());
             } else if (WarehouseTypeEnum.HQZY.getType().equals(item.getFBilltype())) {
                 // 货转在库天数:业务日期-计费日期
                 // 货转计费天数:出库在库天数
-                fInventoryDays = DateUtils.getDateDay(item.getFBsdate(), item.getFChargedate());
-                fBillingDays = fInventoryDays;
-                storageFeesDto.setStartTime(item.getFBsdate());
-                storageFeesDto.setEndTime(item.getFOriginalbilldate());
+                fInventoryDays = DateUtils.getDateDay(item.getFBsdate(), item.getFOriginalbilldate());
+                fBillingDays = DateUtils.getDateDay(item.getFBsdate(), item.getFChargedate());
+                storageFeesDto.setStartTime(item.getFChargedate());
+                storageFeesDto.setEndTime(item.getFBsdate());
             } else {
                 // 库存总帐在库天数:计费截止日期-原始入库日期
                 // 库存总帐计费天数:计费截止日期-计费日期
@@ -4135,8 +4135,7 @@ public class TWarehouseBillsServiceImpl implements ITWarehouseBillsService {
             fees.setCreateBy(loginUser.getUser().getUserName());
             fees.setfWarehouseid(storageFeesDto.getWarehouseId());
             fees.setfProductName(item.getGoodsName());
-            if (WarehouseTypeEnum.SJCK.getType().equals(item.getFBilltype()) ||
-                    WarehouseTypeEnum.HQZY.getType().equals(item.getFBilltype())) {
+            if (WarehouseTypeEnum.SJCK.getType().equals(item.getFBilltype()) || WarehouseTypeEnum.HQZY.getType().equals(item.getFBilltype())) {
                 fees.setfBillingDeadline(item.getFBsdate());
             } else {
                 fees.setfBillingDeadline(warehouseBills.getfBillingDeadline());
@@ -4487,16 +4486,16 @@ public class TWarehouseBillsServiceImpl implements ITWarehouseBillsService {
                 fGoodsid = "\"" + fGoodsid + "\"";
             }
             storageFeesDto.setfGoodsid(fGoodsid);
-            long fId = Long.valueOf(String.valueOf(item.get("fId")));
+            long fId = Long.parseLong(String.valueOf(item.get("fId")));
             // 累计计费天数
             storageFeesDto.setEarlySumDays(DateUtils.getDateDay((Date) item.get("fChargedate"), (Date) item.get("fOriginalbilldate")));
             // 库存天数
-            long fInventoryDays = 0L;
+            long fInventoryDays;
             // 要计费天数
             long fBillingDays = DateUtils.getDateDay(warehouseBills.getfBillingDeadline(), (Date) item.get("fOriginalbilldate"));
             if ("SJCK".equals(fBilltype)) {
                 fInventoryDays = DateUtils.getDateDay(fBsdate, (Date) item.get("fChargedate"));
-                fBillingDays = fInventoryDays;
+                fBillingDays = DateUtils.getDateDay((Date) item.get("fChargedate"), (Date) item.get("fOriginalbilldate"));
                 storageFeesDto.setStartTime((Date) item.get("fChargedate"));
                 storageFeesDto.setEndTime(fBsdate);
             } else if (WarehouseTypeEnum.HQZY.getType().equals(fBilltype)) {