瀏覽代碼

利润结算表

yzc 1 年之前
父節點
當前提交
c2bc7c9493

+ 53 - 0
hx-jxst/src/main/java/com/fjhx/jxst/controller/settlement/SettlementController.java

@@ -0,0 +1,53 @@
+package com.fjhx.jxst.controller.settlement;
+
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.fjhx.jxst.entity.sales.dto.SalesContractDto;
+import com.fjhx.jxst.entity.sales.dto.SalesContractSelectDto;
+import com.fjhx.jxst.entity.statement.bo.SettlementBo;
+import com.fjhx.jxst.service.sales.SalesContractService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * <p>
+ * 利润结算表 前端控制器
+ * </p>
+ *
+ * @author
+ * @since 2023-11-26
+ */
+@RestController
+@RequestMapping("/settlement")
+public class SettlementController {
+
+    @Autowired
+    private SalesContractService salesContractService;
+
+    /**
+     * 利润结算表
+     */
+    @PostMapping("/getProfitClearingPage")
+    Page<SettlementBo> getProfitClearingPage(@RequestBody SalesContractSelectDto dto) {
+        return salesContractService.getProfitClearingPage(dto);
+    }
+
+    /**
+     * 利润结算表头部统计
+     */
+    @PostMapping("/getProfitClearingHead")
+    SettlementBo getProfitClearingHead(@RequestBody SalesContractSelectDto dto) {
+        return salesContractService.getProfitClearingHead(dto);
+    }
+
+    /**
+     * 预算
+     */
+    @PostMapping("/budget")
+    void budget(@RequestBody SalesContractDto dto){
+        salesContractService.budget(dto);
+    }
+
+}

+ 17 - 0
hx-jxst/src/main/java/com/fjhx/jxst/entity/sales/po/SalesContract.java

@@ -129,4 +129,21 @@ public class SalesContract extends BasePo {
      */
     private Integer isSettled;
 
+    /**
+     * 拖车费
+     */
+    private BigDecimal trailerFee;
+    /**
+     * 验收红包
+     */
+    private BigDecimal inspectionRedPackFee;
+    /**
+     * 佣金
+     */
+    private BigDecimal commissionFee;
+    /**
+     * 其他费用
+     */
+    private BigDecimal otherFee;
+
 }

+ 67 - 0
hx-jxst/src/main/java/com/fjhx/jxst/entity/statement/bo/SettlementBo.java

@@ -0,0 +1,67 @@
+package com.fjhx.jxst.entity.statement.bo;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import java.math.BigDecimal;
+
+@Getter
+@Setter
+public class SettlementBo {
+    /**
+     * 销售合同号
+     */
+    private String salesContractCode;
+    /**
+     * 客户id
+     */
+    private Long customerId;
+    /**
+     * 客户名称
+     */
+    private String customerName;
+    /**
+     * 总收入
+     */
+    private BigDecimal totalIncome;
+    /**
+     * 总支出
+     */
+    private BigDecimal totalExpenditure;
+    /**
+     * 毛利率
+     */
+    private BigDecimal grossProfitMargin;
+    /**
+     * 毛利
+     */
+    private BigDecimal grossProfit;
+    /**
+     * 合同金额
+     */
+    private BigDecimal contractAmount;
+    /**
+     * 物料成本
+     */
+    private BigDecimal materialFee;
+    /**
+     * 售后费用
+     */
+    private BigDecimal afterSalesFee;
+    /**
+     * 拖车费
+     */
+    private BigDecimal trailerFee;
+    /**
+     * 验收红包
+     */
+    private BigDecimal inspectionRedPackFee;
+    /**
+     * 佣金
+     */
+    private BigDecimal commissionFee;
+    /**
+     * 其他费用
+     */
+    private BigDecimal otherFee;
+}

+ 13 - 0
hx-jxst/src/main/java/com/fjhx/jxst/mapper/sales/SalesContractMapper.java

@@ -4,9 +4,12 @@ import com.fjhx.jxst.entity.sales.po.SalesContract;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.fjhx.jxst.entity.sales.vo.SalesContractVo;
+import com.fjhx.jxst.entity.statement.bo.SettlementBo;
 import com.ruoyi.common.utils.wrapper.IWrapper;
 import org.apache.ibatis.annotations.Param;
 
+import java.util.List;
+
 
 /**
  * <p>
@@ -23,4 +26,14 @@ public interface SalesContractMapper extends BaseMapper<SalesContract> {
      */
     Page<SalesContractVo> getPage(@Param("page") Page<Object> page, @Param("ew") IWrapper<SalesContract> wrapper);
 
+    /**
+     * 利润结算表
+     */
+    Page<SettlementBo> getProfitClearingPage(@Param("page") Page<Object> page, @Param("ew") IWrapper<SalesContract> wrapper);
+
+    /**
+     * 利润结算表头部统计
+     */
+    SettlementBo getProfitSettlementHead(@Param("ew") IWrapper<SalesContract> wrapper);
+
 }

+ 16 - 0
hx-jxst/src/main/java/com/fjhx/jxst/service/sales/SalesContractService.java

@@ -1,6 +1,7 @@
 package com.fjhx.jxst.service.sales;
 
 import com.fjhx.jxst.entity.sales.po.SalesContract;
+import com.fjhx.jxst.entity.statement.bo.SettlementBo;
 import com.ruoyi.common.core.service.BaseService;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.fjhx.jxst.entity.sales.vo.SalesContractVo;
@@ -37,4 +38,19 @@ public interface SalesContractService extends BaseService<SalesContract> {
      * 合同结清
      */
     void settle(SalesContractDto dto);
+
+    /**
+     * 利润结算表
+     */
+    Page<SettlementBo> getProfitClearingPage( SalesContractSelectDto dto);
+
+    /**
+     * 利润结算表头部统计
+     */
+    SettlementBo getProfitClearingHead(SalesContractSelectDto dto);
+
+    /**
+     * 预算
+     */
+    void budget(SalesContractDto dto);
 }

+ 114 - 6
hx-jxst/src/main/java/com/fjhx/jxst/service/sales/impl/SalesContractServiceImpl.java

@@ -24,15 +24,19 @@ import com.fjhx.jxst.entity.sales.po.SalesContract;
 import com.fjhx.jxst.entity.sales.po.SalesContractDetails;
 import com.fjhx.jxst.entity.sales.vo.SalesContractDetailsVo;
 import com.fjhx.jxst.entity.sales.vo.SalesContractVo;
+import com.fjhx.jxst.entity.statement.bo.SettlementBo;
 import com.fjhx.jxst.mapper.sales.SalesContractMapper;
 import com.fjhx.jxst.service.sales.SalesContractDetailsService;
 import com.fjhx.jxst.service.sales.SalesContractService;
 import com.ruoyi.common.core.domain.BasePo;
 import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.common.utils.wrapper.IWrapper;
+import com.ruoyi.common.utils.wrapper.SqlField;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.util.Arrays;
 import java.util.Date;
 import java.util.List;
@@ -74,10 +78,10 @@ public class SalesContractServiceImpl extends ServiceImpl<SalesContractMapper, S
             if (ObjectUtil.isNotEmpty(list)) {
                 List<Long> ids = list.stream().map(Customer::getId).collect(Collectors.toList());
                 wrapper.and(q -> q.in(SalesContract::getCustomerId, ids).or().like(SalesContractVo::getContractAmount, dto.getKeyword()));
-            }else{
+            } else {
                 wrapper.and(q -> q
                         .like(SalesContractVo::getContractAmount, dto.getKeyword())
-                        .or().like(SalesContract::getCode,dto.getKeyword())
+                        .or().like(SalesContract::getCode, dto.getKeyword())
                 );
             }
         }
@@ -94,7 +98,7 @@ public class SalesContractServiceImpl extends ServiceImpl<SalesContractMapper, S
         });
 
         //计算未到账金额(未结清金额)
-        records.forEach(item->item.setNotClaimAmount(item.getContractAmount().subtract(item.getClaimAmount())));
+        records.forEach(item -> item.setNotClaimAmount(item.getContractAmount().subtract(item.getClaimAmount())));
 
         return page;
     }
@@ -102,7 +106,7 @@ public class SalesContractServiceImpl extends ServiceImpl<SalesContractMapper, S
     @Override
     public SalesContractVo detail(Long id) {
         SalesContract salesContract = this.getById(id);
-        Assert.notEmpty(salesContract,"查询不到合同信息");
+        Assert.notEmpty(salesContract, "查询不到合同信息");
         SalesContractVo result = BeanUtil.toBean(salesContract, SalesContractVo.class);
         List<SalesContractDetails> salesContractDetailsList = salesContractDetailsService.list(q -> q.eq(SalesContractDetails::getSalesContractId, result.getId()));
         List<SalesContractDetailsVo> salesContractDetailsVos = BeanUtil.copyToList(salesContractDetailsList, SalesContractDetailsVo.class);
@@ -115,7 +119,7 @@ public class SalesContractServiceImpl extends ServiceImpl<SalesContractMapper, S
         result.setContractDetailsList(salesContractDetailsVos);
         //赋值客户信息
         Customer customer = customerService.getById(result.getCustomerId());
-        if(ObjectUtil.isNotEmpty(customer)){
+        if (ObjectUtil.isNotEmpty(customer)) {
             result.setCustomerName(customer.getName());
             result.setCustomerBank(customer.getBeneficiaryBank());
             result.setCustomerSwiftCode(customer.getSwiftCode());
@@ -162,7 +166,7 @@ public class SalesContractServiceImpl extends ServiceImpl<SalesContractMapper, S
 //        }
 //        salesContractDto.setContractAmount(count);
 //        salesContractDto.setCode(CodeEnum.SALES_CONTRACT.getCode());
-        salesContractDto.setCode(codingRuleService.createCode(CodingRuleEnum.JXST_SALES_CONTRACT.getKey(),null));
+        salesContractDto.setCode(codingRuleService.createCode(CodingRuleEnum.JXST_SALES_CONTRACT.getKey(), null));
 
         this.save(salesContractDto);
         for (SalesContractDetails salesContractDetails : salesContractDetailsList) {
@@ -184,4 +188,108 @@ public class SalesContractServiceImpl extends ServiceImpl<SalesContractMapper, S
         );
     }
 
+
+    /**
+     * 利润结算表
+     */
+    @Override
+    public Page<SettlementBo> getProfitClearingPage(SalesContractSelectDto dto) {
+        IWrapper<SalesContract> wrapper = getProfitClearingWrapper(dto);
+        wrapper.orderByDesc("sc", SalesContract::getCreateTime);
+        Page<SettlementBo> profitClearingPage = baseMapper.getProfitClearingPage(dto.getPage(), wrapper);
+        List<SettlementBo> records = profitClearingPage.getRecords();
+        if (ObjectUtil.isEmpty(records)) {
+            return profitClearingPage;
+        }
+
+        //计算 总支出 毛利 毛利率
+        for (SettlementBo record : records) {
+            //总支出
+            BigDecimal totalExpenditure = BigDecimal.ZERO;
+            totalExpenditure.add(record.getMaterialFee());//物料费
+            totalExpenditure.add(record.getAfterSalesFee());//售后费用
+            totalExpenditure.add(record.getTrailerFee());//拖车费
+            totalExpenditure.add(record.getInspectionRedPackFee());//验货红包
+            totalExpenditure.add(record.getCommissionFee());//佣金
+            totalExpenditure.add(record.getOtherFee());//其他费用
+            record.setTotalExpenditure(totalExpenditure);
+
+            //毛利(总收入-总支出)
+            record.setGrossProfit(record.getTotalIncome().subtract(record.getTotalExpenditure()));
+
+            //毛利率(毛利/总收入*100%)
+            BigDecimal grossProfitMargin = BigDecimal.ZERO;
+            if (record.getGrossProfit().compareTo(BigDecimal.ZERO) > 0) {
+                grossProfitMargin = record.getGrossProfit()
+                        .divide(record.getTotalIncome(), 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
+            }
+            record.setGrossProfitMargin(grossProfitMargin);
+
+            //变成科学计数法问题处理
+            record.setMaterialFee(record.getMaterialFee().setScale(4, RoundingMode.HALF_UP));
+        }
+
+        return profitClearingPage;
+    }
+
+    /**
+     * 利润结算表头部统计
+     */
+    @Override
+    public SettlementBo getProfitClearingHead(SalesContractSelectDto dto) {
+        IWrapper<SalesContract> wrapper = getProfitClearingWrapper(dto);
+        SettlementBo record = baseMapper.getProfitSettlementHead(wrapper);
+
+        //总支出
+        BigDecimal totalExpenditure = BigDecimal.ZERO;
+        totalExpenditure.add(record.getMaterialFee());//物料费
+        totalExpenditure.add(record.getAfterSalesFee());//售后费用
+        totalExpenditure.add(record.getTrailerFee());//拖车费
+        totalExpenditure.add(record.getInspectionRedPackFee());//验货红包
+        totalExpenditure.add(record.getCommissionFee());//佣金
+        totalExpenditure.add(record.getOtherFee());//其他费用
+        record.setTotalExpenditure(totalExpenditure);
+
+        //毛利(总收入-总支出)
+        record.setGrossProfit(record.getTotalIncome().subtract(record.getTotalExpenditure()));
+
+        //毛利率(毛利/总收入*100%)
+        BigDecimal grossProfitMargin = BigDecimal.ZERO;
+        if (record.getGrossProfit().compareTo(BigDecimal.ZERO) > 0) {
+            grossProfitMargin = record.getGrossProfit()
+                    .divide(record.getTotalIncome(), 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
+        }
+        record.setGrossProfitMargin(grossProfitMargin);
+
+        //变成科学计数法问题处理
+        record.setMaterialFee(record.getMaterialFee().setScale(4, RoundingMode.HALF_UP));
+
+        return record;
+    }
+
+    /**
+     * 利润结算表公用参数列表
+     */
+    private IWrapper<SalesContract> getProfitClearingWrapper(SalesContractSelectDto dto) {
+        IWrapper<SalesContract> wrapper = IWrapper.getWrapper();
+        wrapper.keyword(dto.getKeyword(),
+                new SqlField("cu.name"),
+                new SqlField("sc.code")
+        );
+
+        wrapper.eq("sc.is_settled", dto.getIsSettled());
+
+        return wrapper;
+    }
+
+    /**
+     * 预算
+     */
+    @Override
+    public void budget(SalesContractDto dto) {
+        Assert.notEmpty(dto.getId(), "");
+        SalesContract salesContract = this.getById(dto.getId());
+        Assert.notEmpty(salesContract,"查询不到合同信息!");
+        this.updateById(dto);
+    }
 }

+ 62 - 0
hx-jxst/src/main/resources/mapper/sales/SalesContractMapper.xml

@@ -21,5 +21,67 @@
         from sales_contract sc
             ${ew.customSqlSegment}
     </select>
+    <select id="getProfitClearingPage" resultType="com.fjhx.jxst.entity.statement.bo.SettlementBo">
+        <include refid="getProfitClearing"/>
+    </select>
+    <select id="getProfitSettlementHead" resultType="com.fjhx.jxst.entity.statement.bo.SettlementBo">
+        SELECT
+            sum( totalIncome ) AS totalIncome,
+            sum( materialFee ) AS materialFee,
+            sum( afterSalesFee ) AS afterSalesFee,
+            sum( trailerFee ) AS trailerFee,
+            sum( inspectionRedPackFee ) AS inspectionRedPackFee,
+            sum( commissionFee ) AS commissionFee,
+            sum( otherFee ) AS otherFee,
+            sum( contractAmount ) AS contractAmount
+        FROM
+            (
+                <include refid="getProfitClearing"/>
+            ) t1
+    </select>
+
+    <sql id="getProfitClearing">
+        SELECT
+            sc.`code` AS salesContractCode,
+            sc.customer_id,
+            cu.`name` AS customerName,
+            ( SELECT IFNULL( sum( cc.contract_money ), 0 ) FROM bytesailing_sale.claim_contract cc WHERE cc.contract_id = sc.id ) AS totalIncome,
+            sc.contract_amount AS contractAmount,
+            (
+                SELECT
+                    IFNULL( sum( sjd.price * sjd.quantity ), 0 )
+                FROM
+                    bytesailing_wms.stock_journal_details sjd
+                        JOIN bytesailing_wms.stock_wait_details swd ON sjd.business_details_id = swd.id
+                        JOIN bytesailing_wms.stock_wait sw ON swd.stock_wait_id = sw.id
+                        JOIN bytesailing_mes.production_task pt ON sw.business_id = pt.id
+                        JOIN bytesailing_mes.production_plan pp ON pt.production_plan_id = pp.id
+                        JOIN bytesailing_mes.work_order wo ON pp.work_order_id = wo.id
+                        JOIN sales_contract_details scd ON wo.contract_details_id = scd.id
+                WHERE
+                    scd.sales_contract_id = sc.id
+            ) AS materialFee,
+            (
+                SELECT
+                    IFNULL( sum( asr.amount ), 0 )
+                FROM
+                    after_sales_record asr
+                        JOIN bytesailing_mes.production_task_detail ptd ON asr.product_sn = ptd.product_sn
+                        JOIN bytesailing_mes.production_task pt ON ptd.production_task_id = pt.id
+                        JOIN bytesailing_mes.production_plan pp ON pt.production_plan_id = pp.id
+                        JOIN bytesailing_mes.work_order wo ON pp.work_order_id = wo.id
+                        JOIN sales_contract_details scd ON wo.contract_details_id = scd.id
+                WHERE
+                    scd.sales_contract_id = sc.id
+            ) AS afterSalesFee,
+            sc.trailer_fee AS trailerFee,
+            sc.inspection_red_pack_fee AS inspectionRedPackFee,
+            sc.commission_fee AS commissionFee,
+            sc.other_fee AS otherFee
+        FROM
+            sales_contract sc
+            LEFT JOIN bytesailing_customer.customer cu ON sc.customer_id = cu.id
+            ${ew.customSqlSegment}
+    </sql>
 
 </mapper>