Browse Source

收费明细计算调整

lzm 2 years ago
parent
commit
7f3ca9106c

+ 15 - 7
sp-server/src/main/java/com/pj/project/tb_fee_details/TbFeeDetailsService.java

@@ -173,13 +173,13 @@ public class TbFeeDetailsService extends ServiceImpl<TbFeeDetailsMapper, TbFeeDe
             BigDecimal[] qr = paidMoney.divideAndRemainder(baseNightPrice);//商和余数的数组,商为夜间停车次数,余数为白天停车费用。
             BigDecimal nightFeeNum = qr[0];
             if(nightFeeNum.compareTo(BigDecimal.valueOf(0)) > 0){
-                nightParkFee.setNum(nightFeeNum.intValue()).setItemTypeName("夜间停车")
-                .setUnitPrice(baseNightPrice).setItemPrice(baseNightPrice.multiply(nightFeeNum));
-                setFee(nightParkFee, car, business, transactionIdStr, outTradeNoStr);
-                saveOrUpdate(nightParkFee);
-                if(qr[1].compareTo(BigDecimal.valueOf(0)) == 0 && dayParkFee.getId() != null){
-                    delete(Long.valueOf(dayParkFee.getId()));
-                }
+                    nightParkFee.setNum(nightFeeNum.intValue()).setItemTypeName("夜间停车")
+                            .setUnitPrice(baseNightPrice).setItemPrice(baseNightPrice.multiply(nightFeeNum));
+                    setFee(nightParkFee, car, business, transactionIdStr, outTradeNoStr);
+                    saveOrUpdate(nightParkFee);
+                    if(qr[1].compareTo(BigDecimal.valueOf(0)) == 0 && dayParkFee.getId() != null){
+                        delete(Long.valueOf(dayParkFee.getId()));
+                    }
             }
             if(qr[1].compareTo(BigDecimal.valueOf(0)) > 0){
                 dayParkFee.setNum(1).setItemTypeName("白天停车").setUnitPrice(qr[1]).setItemPrice(qr[1]);
@@ -196,7 +196,9 @@ public class TbFeeDetailsService extends ServiceImpl<TbFeeDetailsMapper, TbFeeDe
         String toDay = DateUtil.format(now, "yyyy-MM-dd");
         parkFee.setTaxRate(partConfig.getTaxRate());
         BigDecimal taxPrice = parkFee.getItemPrice().divide(BigDecimal.valueOf(1).add(parkFee.getTaxRate()),2, BigDecimal.ROUND_HALF_UP).multiply(parkFee.getTaxRate());
+        taxPrice = taxPrice.setScale(2, BigDecimal.ROUND_HALF_UP);
         BigDecimal noTaxPrice = parkFee.getItemPrice().subtract(taxPrice);
+        noTaxPrice = noTaxPrice.setScale(2, BigDecimal.ROUND_HALF_UP);
         parkFee.setBusinessId(car.getBusinessId()).setBusinessCarId(car.getId())
                 .setCarNo(car.getCarNo())
                 .setNoTaxPrice(noTaxPrice).setTaxPrice(taxPrice)
@@ -235,6 +237,8 @@ public class TbFeeDetailsService extends ServiceImpl<TbFeeDetailsMapper, TbFeeDe
         BigDecimal toDayFee = new BigDecimal(0);
         BigDecimal allDayFee = new BigDecimal(0);
         BigDecimal allParkFee = new BigDecimal(0);
+        BigDecimal allDayTaxes = new BigDecimal(0);
+        BigDecimal allDayNoTaxFee = new BigDecimal(0);
 	    List<ExportFeeDetailDTO> exportList = new ArrayList<>();
         List<TbFeeDetails> list = this.getList(so);
         Integer index = 1;
@@ -263,11 +267,15 @@ public class TbFeeDetailsService extends ServiceImpl<TbFeeDetailsMapper, TbFeeDe
                 allParkFee = allParkFee.add(feeDetails.getItemPrice());
             }
             allDayFee = allDayFee.add(feeDetails.getItemPrice());
+            allDayTaxes = allDayTaxes.add(feeDetails.getTaxPrice());
+            allDayNoTaxFee = allDayNoTaxFee.add(feeDetails.getNoTaxPrice());
         }
 
         head.put("toDayFee", toDayFee.toString());
         head.put("allParkFee", allParkFee.toString());
         head.put("allDayFee", allDayFee.toString());
+        head.put("allDayTaxes", allDayTaxes.toString());
+        head.put("allDayNoTaxFee", allDayNoTaxFee.toString());
 
         String separator = File.separator;
         String today = DateUtil.today();

+ 2 - 2
sp-server/src/main/java/com/pj/project/tb_fee_statistics/TbFeeStatisticsMapper.xml

@@ -106,7 +106,7 @@
 	</select>
 
     <select id="getMonth" resultMap="model">
-        select month, fee_type,  sum(num) as num, sum(tax_money) as statistics_money
+        select month, fee_type,  sum(num) as num, sum(tax_money) as statistics_money, sum(taxes) as taxes, sum(no_tax_money) as no_tax_money, any_value(tax_rate)
         from tb_fee_statistics
         <where>
             <if test=' this.has("feeType") '> and fee_type = #{feeType} </if>
@@ -121,7 +121,7 @@
     </select>
 
     <select id="getYear" resultMap="model">
-        select year, fee_type,  sum(num) as num, sum(tax_money) as statistics_money
+        select year, fee_type,  sum(num) as num, sum(tax_money) as statistics_money, sum(taxes) as taxes, sum(no_tax_money) as no_tax_money, any_value(tax_rate)
         from tb_fee_statistics
         <where>
             <if test=' this.has("feeType") '> and fee_type = #{feeType} </if>

+ 37 - 40
sp-server/src/main/java/com/pj/project/tb_fee_statistics/TbFeeStatisticsService.java

@@ -28,6 +28,8 @@ import com.pj.project.tb_business_item.TbBusinessItem;
 import com.pj.project.tb_fee_details.ExportFeeDetailDTO;
 import com.pj.project.tb_fee_details.TbFeeDetails;
 import com.pj.project.tb_fee_details.TbFeeDetailsService;
+import com.pj.project.tb_item_type.TbItemType;
+import com.pj.project.tb_item_type.TbItemTypeService;
 import com.pj.project4sp.uploadfile.UploadUtil;
 import com.pj.utils.so.SoMap;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -64,6 +66,8 @@ public class TbFeeStatisticsService extends ServiceImpl<TbFeeStatisticsMapper, T
     private PartConfig partConfig;
     @Resource
     private MyConfig myConfig;
+    @Resource
+    private TbItemTypeService tbItemTypeService;
 
     /**
      * 增
@@ -102,31 +106,13 @@ public class TbFeeStatisticsService extends ServiceImpl<TbFeeStatisticsMapper, T
 
     List<TbFeeStatistics> getMonth(SoMap so) {
         List<TbFeeStatistics> monthFees = tbFeeStatisticsMapper.getMonth(so);
-        for (TbFeeStatistics fee : monthFees) {
-            BigDecimal taxRate = BigDecimal.valueOf(TbFeeStatistics.taxRate.BUSINESS.getValue());
-            if(fee.getFeeType() == TbFeeStatistics.FeeTypeEnum.PARK_FEE.getCode()){
-                taxRate = BigDecimal.valueOf(TbFeeStatistics.taxRate.PARK.getValue());
-            }
-            BigDecimal taxes = fee.getStatisticsMoney().divide(taxRate.add(BigDecimal.valueOf(1)),2, BigDecimal.ROUND_HALF_UP).multiply(taxRate);
-            taxes = taxes.setScale(2, BigDecimal.ROUND_HALF_UP);
-            BigDecimal noTaxMoney = fee.getStatisticsMoney().subtract(taxes);
-            fee.setTaxRate(taxRate).setTaxes(taxes).setNoTaxMoney(noTaxMoney);
-        }
+
         return monthFees;
     }
 
     List<TbFeeStatistics> getYear(SoMap so) {
         List<TbFeeStatistics> yearFees = tbFeeStatisticsMapper.getYear(so);
-        for (TbFeeStatistics fee : yearFees) {
-            BigDecimal taxRate = BigDecimal.valueOf(TbFeeStatistics.taxRate.BUSINESS.getValue());
-            if(fee.getFeeType() == TbFeeStatistics.FeeTypeEnum.PARK_FEE.getCode()){
-                taxRate = BigDecimal.valueOf(TbFeeStatistics.taxRate.PARK.getValue());
-            }
-            BigDecimal taxes = fee.getStatisticsMoney().divide(taxRate.add(BigDecimal.valueOf(1)),2, BigDecimal.ROUND_HALF_UP).multiply(taxRate);
-            taxes = taxes.setScale(2, BigDecimal.ROUND_HALF_UP);
-            BigDecimal noTaxMoney = fee.getStatisticsMoney().subtract(taxes);
-            fee.setTaxRate(taxRate).setTaxes(taxes).setNoTaxMoney(noTaxMoney);
-        }
+
         return yearFees;
     }
 
@@ -164,12 +150,15 @@ public class TbFeeStatisticsService extends ServiceImpl<TbFeeStatisticsMapper, T
             return;
         }
         parkFee.setNum(totalNum).setTaxMoney(parkFee.getTaxMoney().add(totalPrice));
-        BigDecimal taxes = parkFee.getTaxMoney()
+        BigDecimal taxes = totalPrice
                 .divide(BigDecimal.valueOf(1).add(parkFee.getTaxRate()),2, BigDecimal.ROUND_HALF_UP)
                 .multiply(parkFee.getTaxRate());
-        BigDecimal noTaxMoney = parkFee.getTaxMoney().subtract(taxes);
-//        BigDecimal noTaxMoney = parkFee.getTaxMoney().subtract(parkFee.getTaxMoney().multiply(parkFee.getTaxRate()));
-        parkFee.setNoTaxMoney(noTaxMoney).setTaxes(taxes);
+        taxes = taxes.setScale(2, BigDecimal.ROUND_HALF_UP);
+        BigDecimal noTaxMoney = totalPrice.subtract(taxes);
+        noTaxMoney = noTaxMoney.setScale(2, BigDecimal.ROUND_HALF_UP);
+        parkFee.setNoTaxMoney(parkFee.getNoTaxMoney().add(noTaxMoney))
+                .setTaxes(parkFee.getTaxes().add(taxes));
+
         parkFee.setDayTime(now).setMonth(thisMonth).setYear(thisYear).setDay(toDay)
                 .setFeeType(TbFeeStatistics.FeeTypeEnum.PARK_FEE.getCode()).setItemTypeName(TbFeeStatistics.FeeTypeEnum.PARK_FEE.getDesc())
                 .setPayType(3);
@@ -200,33 +189,39 @@ public class TbFeeStatisticsService extends ServiceImpl<TbFeeStatisticsMapper, T
         String thisYear = StrUtil.sub(toDay, 0, 4);
         String thisMonth = StrUtil.sub(toDay, 0, 7);
         for (TbBusinessItem item : items) {
-            int feeType = -1;
+            Integer feeType = item.getPayType();
             String itemType = item.getItemTypeName();
-            if (itemType.contains("核酸")) {
-                feeType = TbFeeStatistics.FeeTypeEnum.NUCLEIC_FEE.getCode();
-            } else if (itemType.contains("消毒") || itemType.contains("消杀")) {
-                feeType = TbFeeStatistics.FeeTypeEnum.DISINFECT_FEE.getCode();
-            } else if (itemType.contains("装卸")) {
-                feeType = TbFeeStatistics.FeeTypeEnum.STEVEDORE_FEE.getCode();
-            } else if (StrUtil.equals(itemType, "特殊车辆") || StrUtil.equals(itemType, "汽车吊")) {
-                feeType = TbFeeStatistics.FeeTypeEnum.STEVEDORE_FEE.getCode();
-            } else if (itemType.contains("入场管理")) {
-                feeType = TbFeeStatistics.FeeTypeEnum.MANAGE_FEE.getCode();
-            } else if(StrUtil.equals(itemType, "充电打冷")) {
-                feeType = TbFeeStatistics.FeeTypeEnum.CHARGE_FEE.getCode();
+            if(StrUtil.isNotEmpty(itemType)){
+                if (itemType.contains("核酸")) {
+                    feeType = TbFeeStatistics.FeeTypeEnum.NUCLEIC_FEE.getCode();
+                } else if (itemType.contains("消毒") || itemType.contains("消杀")) {
+                    feeType = TbFeeStatistics.FeeTypeEnum.DISINFECT_FEE.getCode();
+                } else if (itemType.contains("装卸")) {
+                    feeType = TbFeeStatistics.FeeTypeEnum.STEVEDORE_FEE.getCode();
+                } else if (StrUtil.equals(itemType, "特殊车辆") || StrUtil.equals(itemType, "汽车吊")) {
+                    feeType = TbFeeStatistics.FeeTypeEnum.STEVEDORE_FEE.getCode();
+                } else if (itemType.contains("入场管理")) {
+                    feeType = TbFeeStatistics.FeeTypeEnum.MANAGE_FEE.getCode();
+                } else if(StrUtil.equals(itemType, "充电打冷")) {
+                    feeType = TbFeeStatistics.FeeTypeEnum.CHARGE_FEE.getCode();
+                }
             }
+
+            Double taxRate = item.getTaxRate();
+
             TbFeeStatistics businessFee = this.getByDayAndFeeType(toDay, feeType);
             if (businessFee == null) {
                 businessFee = new TbFeeStatistics();
-                businessFee.setTaxRate(BigDecimal.valueOf(TbFeeStatistics.taxRate.BUSINESS.getValue()));
+                businessFee.setTaxRate(BigDecimal.valueOf(taxRate));
             }
             businessFee.setTaxMoney(businessFee.getTaxMoney().add(item.getTotal()));//含税收入
-            //businessFee.setNum(businessFee.getNum() + 1);
             businessFee.setNum(businessFee.getNum() + Integer.valueOf(item.getNum()));
             BigDecimal taxes = businessFee.getTaxMoney()
                     .divide(BigDecimal.valueOf(1).add(businessFee.getTaxRate()),2, BigDecimal.ROUND_HALF_UP)
                     .multiply(businessFee.getTaxRate());
+            taxes = taxes.setScale(2, BigDecimal.ROUND_HALF_UP);
             BigDecimal noTaxMoney = businessFee.getTaxMoney().subtract(taxes);
+            noTaxMoney = noTaxMoney.setScale(2, BigDecimal.ROUND_HALF_UP);
 
             businessFee.setNoTaxMoney(noTaxMoney).setTaxes(taxes);
             businessFee.setDayTime(now).setMonth(thisMonth).setYear(thisYear).setDay(toDay)
@@ -241,13 +236,15 @@ public class TbFeeStatisticsService extends ServiceImpl<TbFeeStatisticsMapper, T
             TbFeeDetails businessFeeDetail = null;
             if (businessFeeDetail == null) {
                 businessFeeDetail = new TbFeeDetails();
-                businessFeeDetail.setTaxRate(BigDecimal.valueOf(TbFeeStatistics.taxRate.BUSINESS.getValue()));
+                businessFeeDetail.setTaxRate(BigDecimal.valueOf(taxRate));
             }
 
             BigDecimal taxPrice = item.getItemPrice()
                     .divide(BigDecimal.valueOf(1).add(businessFeeDetail.getTaxRate()),2, BigDecimal.ROUND_HALF_UP)
                     .multiply(businessFeeDetail.getTaxRate());
+            taxPrice = taxPrice.setScale(2, BigDecimal.ROUND_HALF_UP);
             BigDecimal noTaxPrice = item.getItemPrice().subtract(taxPrice);
+            noTaxPrice = noTaxPrice.setScale(2, BigDecimal.ROUND_HALF_UP);
             String carNo = business.getCardNo();
             if(StrUtil.isEmpty(business.getCardNo())){
                 carNo = business.getChinaCarNo();

BIN
sp-server/src/main/resources/static/day-fee-new.xlsx