caozj преди 2 години
родител
ревизия
80cbcb90ba

+ 4 - 0
hx-account/src/main/java/com/fjhx/account/entity/account/vo/AccountRequestFundsDetailVo.java

@@ -14,4 +14,8 @@ import lombok.Setter;
 @Setter
 public class AccountRequestFundsDetailVo extends AccountRequestFundsDetail {
 
+    /**
+     * 币种
+     */
+    private String currency;
 }

+ 8 - 0
hx-account/src/main/java/com/fjhx/account/mapper/account/AccountRequestFundsDetailMapper.java

@@ -7,6 +7,8 @@ import com.fjhx.account.entity.account.vo.AccountRequestFundsDetailVo;
 import com.ruoyi.common.utils.wrapper.IWrapper;
 import org.apache.ibatis.annotations.Param;
 
+import java.util.List;
+
 
 /**
  * <p>
@@ -23,4 +25,10 @@ public interface AccountRequestFundsDetailMapper extends BaseMapper<AccountReque
      */
     Page<AccountRequestFundsDetailVo> getPage(@Param("page") Page<Object> page, @Param("ew") IWrapper<AccountRequestFundsDetail> wrapper);
 
+    /**
+     * 获取列表根据合同ID
+     * @param contractId
+     * @return
+     */
+    List<AccountRequestFundsDetailVo> getListByContractId(Long contractId);
 }

+ 9 - 0
hx-account/src/main/java/com/fjhx/account/service/account/AccountRequestFundsDetailService.java

@@ -7,6 +7,8 @@ import com.fjhx.account.entity.account.vo.AccountRequestFundsDetailVo;
 import com.fjhx.account.entity.account.dto.AccountRequestFundsDetailSelectDto;
 import com.fjhx.account.entity.account.dto.AccountRequestFundsDetailDto;
 
+import java.util.List;
+
 
 /**
  * <p>
@@ -43,4 +45,11 @@ public interface AccountRequestFundsDetailService extends BaseService<AccountReq
      */
     void delete(Long id);
 
+    /**
+     * 根据合同ID获取列表
+     * @param contractId
+     * @return
+     */
+    List<AccountRequestFundsDetailVo> getListByContractId(Long contractId);
+
 }

+ 12 - 0
hx-account/src/main/java/com/fjhx/account/service/account/impl/AccountRequestFundsDetailServiceImpl.java

@@ -12,6 +12,8 @@ import com.ruoyi.common.utils.wrapper.IWrapper;
 import com.fjhx.account.entity.account.dto.AccountRequestFundsDetailDto;
 import cn.hutool.core.bean.BeanUtil;
 
+import java.util.List;
+
 
 /**
  * <p>
@@ -54,4 +56,14 @@ public class AccountRequestFundsDetailServiceImpl extends ServiceImpl<AccountReq
         this.removeById(id);
     }
 
+    /**
+     * 获取列表根据合同ID
+     * @param contractId
+     * @return
+     */
+    @Override
+    public List<AccountRequestFundsDetailVo> getListByContractId(Long contractId) {
+        return baseMapper.getListByContractId(contractId);
+    }
+
 }

+ 12 - 0
hx-account/src/main/resources/mapper/account/AccountRequestFundsDetailMapper.xml

@@ -16,4 +16,16 @@
             ${ew.customSqlSegment}
     </select>
 
+    <select id="getListByContractId" resultType="com.fjhx.account.entity.account.vo.AccountRequestFundsDetailVo">
+        SELECT
+            t2.currency,
+            t1.*
+        FROM
+            account_request_funds_detail t1
+        LEFT JOIN account_request_funds t2 ON t1.account_request_funds_id = t2.id
+        LEFT JOIN account_payment t3 ON t2.id = t3.business_id
+        WHERE
+            t1.contract_id = #{contractId}
+          AND t3.`status` = 20
+    </select>
 </mapper>

+ 9 - 0
hx-sale/src/main/java/com/fjhx/sale/controller/contract/ContractController.java

@@ -179,4 +179,13 @@ public class ContractController {
     public  Page<ContractBudgetVo> getProfitBudgetPage(@RequestBody ContractSelectDto dto){
         return  contractService.getProfitBudgetPage(dto);
     }
+
+    /**
+     * 利润结算
+     */
+    @PostMapping("/getProfitClearingPage")
+    public  Page<ContractBudgetVo> getProfitClearingPage(@RequestBody ContractSelectDto dto){
+        return  contractService.getProfitClearingPage(dto);
+    }
+
 }

+ 9 - 0
hx-sale/src/main/java/com/fjhx/sale/entity/contract/po/Contract.java

@@ -279,6 +279,15 @@ public class Contract extends BasePo {
     private String budgetRemark;
 
     /**
+     * 利润结算表代理费
+     */
+    private BigDecimal profitAgencyFee;
+
+    /**
+     * 利润结算表备注
+     */
+    private String profitClearingRemark;
+    /**
      * 版本号
      */
     @TableField(fill = FieldFill.INSERT)

+ 32 - 0
hx-sale/src/main/java/com/fjhx/sale/entity/contract/vo/ContractBudgetVo.java

@@ -23,6 +23,27 @@ public class ContractBudgetVo extends Contract {
      * 合同产品IDS
      */
     private String contractProductIds;
+
+    /**
+     * 检验费
+     */
+    private BigDecimal checkout;
+
+    /**
+     * 验货费
+     */
+    private BigDecimal inspectionCharge;
+
+    /**
+     * 运费
+     */
+    private BigDecimal freight;
+
+    /**
+     * 产地证费
+     */
+    private BigDecimal certificateOfOrigin;
+
     /**
      * 拖车费币种
      */
@@ -147,4 +168,15 @@ public class ContractBudgetVo extends Contract {
      * 采购合同总金额
      */
     private BigDecimal sumPurchaseContractMoney;
+
+    /**
+     * 其他收入
+     */
+    private BigDecimal otherIncomeAmount;
+
+    /**
+     * 已付货款
+     */
+    private BigDecimal accountPaid;
+
 }

+ 140 - 10
hx-sale/src/main/java/com/fjhx/sale/service/contract/impl/ContractServiceImpl.java

@@ -14,7 +14,10 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.fjhx.account.controller.utils.DateUtils;
 import com.fjhx.account.entity.account.po.AccountManagement;
+import com.fjhx.account.entity.account.po.AccountRequestFundsDetail;
+import com.fjhx.account.entity.account.vo.AccountRequestFundsDetailVo;
 import com.fjhx.account.service.account.AccountManagementService;
+import com.fjhx.account.service.account.AccountRequestFundsDetailService;
 import com.fjhx.area.service.SetCustomizeAreaId;
 import com.fjhx.area.utils.CustomizeAreaUtil;
 import com.fjhx.common.constant.SourceConstant;
@@ -124,6 +127,9 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
     @Autowired
     private ClaimContractService claimContractService;
 
+    @Autowired
+    private AccountRequestFundsDetailService accountRequestFundsDetailService;
+
     /**
      * 分页
      *
@@ -189,9 +195,6 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
      */
     @Override
     public Page<ContractBudgetVo> getProfitBudgetPage(ContractSelectDto dto) {
-        if(StringUtils.isEmpty(SecurityUtils.getTenantId())){
-            throw new ServiceException("租户ID不能为空");
-        }
         IWrapper<Contract> wrapper = getWrapper();
         wrapper.orderByDesc("t1", Contract::getCreateTime);
         wrapper.between("t1", Contract::getStatus, FlowStatusEnum.PASS.getKey(), FlowStatusEnum.CANCELLATION.getKey() - 1);
@@ -291,9 +294,6 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
      */
     @Override
     public Page<ContractBudgetVo> getProfitClearingPage(ContractSelectDto dto) {
-        if(StringUtils.isEmpty(SecurityUtils.getTenantId())){
-            throw new ServiceException("租户ID不能为空");
-        }
         IWrapper<Contract> wrapper = getWrapper();
         wrapper.orderByDesc("t1", Contract::getCreateTime);
         wrapper.between("t1", Contract::getStatus, FlowStatusEnum.PASS.getKey(), FlowStatusEnum.CANCELLATION.getKey() - 1);
@@ -313,6 +313,8 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
         Map<String,BigDecimal> defaultCurrencyRateMap = defaultCurrencyRateList.stream().collect(Collectors.toMap(CurrencyRate::getType,CurrencyRate::getRate));
         for(ContractBudgetVo v : list){
             v.setRefundableAmount(BigDecimal.ZERO);//暂时先设置退税金额为0
+            v.setOtherIncomeAmount(BigDecimal.ZERO);//暂时先设置其他收入为0
+            v.setAccountPaid(BigDecimal.ZERO);//暂时先设置已付货款为0
             // 赋值客户名称
             customerService.attributeAssign(list, Contract::getBuyCorporationId, (item, customer) -> {
                 item.setCustomerName(customer.getName());
@@ -321,18 +323,41 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
                 //取出汇率
                 List<CurrencyRate> assignCurrencyRatesList = JSON.parseArray(v.getCurrencyRateJson(), CurrencyRate.class);
                 Map<String,BigDecimal> assignCurrencyRatesMap = assignCurrencyRatesList.stream().collect(Collectors.toMap(CurrencyRate::getType,CurrencyRate::getRate));
-                v.setEhsdSumAmount(v.getAmount().multiply(assignCurrencyRatesMap.getOrDefault(v.getCurrency(),BigDecimal.ONE)));//计算汇算人民币
+                v.setRmbContractAmount(v.getAmount().multiply(assignCurrencyRatesMap.getOrDefault(v.getCurrency(),BigDecimal.ONE)));//计算汇算人民币
                 //到账金额
                 v.setSumClaimMoney(this.getSumClaimMoney(v,assignCurrencyRatesMap));
                 //采购合同总金额
                 v.setSumPurchaseContractMoney(this.getSumPurchaseContractMoney(v,assignCurrencyRatesMap));
+                //支出费用
+                this.getGroupTypeMoney(v,assignCurrencyRatesMap);
             }else{//没有取默认的汇率
-                v.setEhsdSumAmount(v.getAmount().multiply(defaultCurrencyRateMap.getOrDefault(v.getCurrency(),BigDecimal.ONE)));//计算汇算人民币
+                v.setRmbContractAmount(v.getAmount().multiply(defaultCurrencyRateMap.getOrDefault(v.getCurrency(),BigDecimal.ONE)));//计算汇算人民币
                 //到账金额
                 v.setSumClaimMoney(this.getSumClaimMoney(v,defaultCurrencyRateMap));
                 //采购合同总金额
                 v.setSumPurchaseContractMoney(this.getSumPurchaseContractMoney(v,defaultCurrencyRateMap));
+                //支出费用
+                this.getGroupTypeMoney(v,defaultCurrencyRateMap);
             }
+            //计算收入总计=合同金额(转人民币)+应退税金额(转人民币)+其他收入(转人民币)
+            v.setIncomeAmount(v.getRmbContractAmount()==null?BigDecimal.ZERO:v.getRmbContractAmount().add(v.getRefundableAmount()).add(v.getOtherIncomeAmount()));
+            //计算支出总计 除合同金额(转人民币)+应退税金额(转人民币)+其他收入(转人民币) 其他金额相加
+            v.setExpenditureAmount(v.getTrailerFee().add
+                    (v.getCustomsFee()).add
+                    (v.getPortMixedFee()).add
+                    (v.getInspectionRedPack()).add
+                    (v.getCommission()).add
+                    (v.getOther()).add
+                    (v.getCheckout()).add
+                    (v.getInspectionCharge()).add
+                    (v.getFreight()).add
+                    (v.getCertificateOfOrigin()).add
+                    (v.getAccountPaid()).add
+                    (v.getProfitAgencyFee()));
+            //计算毛利 收入-支出
+            v.setGross(v.getIncomeAmount().subtract(v.getExpenditureAmount()));
+            //计算毛利率 毛利/收入
+            v.setGrossRate(v.getGross().divide(v.getIncomeAmount(), RoundingMode.CEILING));
 
         }
         return page;
@@ -961,7 +986,7 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
         BigDecimal sumClaimMOney = BigDecimal.ZERO;
         if(CollectionUtils.isNotEmpty(claimContractList)){
             for(ClaimContract c:claimContractList){
-                sumClaimMOney.add(c.getMoney().multiply(currencyRatesMap.getOrDefault(c.getCurrency(),BigDecimal.ONE)));
+                sumClaimMOney = sumClaimMOney.add(c.getMoney().multiply(currencyRatesMap.getOrDefault(c.getCurrency(),BigDecimal.ONE)));
             }
             return sumClaimMOney;
         }else{
@@ -980,7 +1005,7 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
         BigDecimal sumPurchaseContractMoney = BigDecimal.ZERO;
         if(CollectionUtils.isNotEmpty(list)){
             for(EhsdPurchaseProductVo c:list){
-                sumPurchaseContractMoney.add(c.getAmount().multiply(currencyRatesMap.getOrDefault(c.getCurrency(),BigDecimal.ONE)));
+                sumPurchaseContractMoney = sumPurchaseContractMoney.add(c.getAmount().multiply(currencyRatesMap.getOrDefault(c.getCurrency(),BigDecimal.ONE)));
             }
             return sumPurchaseContractMoney;
         }else{
@@ -988,4 +1013,109 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
         }
     }
 
+    /**
+     * 统计支出各种费用
+     * @param v
+     * @param currencyRatesMap 汇率JSON
+     * @return
+     */
+    private void getGroupTypeMoney(ContractBudgetVo v,Map<String,BigDecimal> currencyRatesMap){
+        List<AccountRequestFundsDetailVo> list = accountRequestFundsDetailService.getListByContractId(v.getContractId());
+        /**
+         * 拖车费
+         */
+        BigDecimal trailerFee = BigDecimal.ZERO;
+
+        /**
+         * 报关费
+         */
+        BigDecimal customsFee = BigDecimal.ZERO;
+
+        /**
+         * 港杂费
+         */
+        BigDecimal portMixedFee = BigDecimal.ZERO;
+
+        /**
+         * 验货红包
+         */
+        BigDecimal inspectionRedPack = BigDecimal.ZERO;
+
+        /**
+         * 佣金
+         */
+        BigDecimal commission = BigDecimal.ZERO;
+
+        /**
+         * 检验费
+         */
+        BigDecimal checkout = BigDecimal.ZERO;
+
+        /**
+         * 验货费
+         */
+        BigDecimal inspectionCharge = BigDecimal.ZERO;
+
+        /**
+         * 运费
+         */
+        BigDecimal freight = BigDecimal.ZERO;
+
+        /**
+         * 产地证费
+         */
+        BigDecimal certificateOfOrigin = BigDecimal.ZERO;
+
+        /**
+         * 其他费用
+         */
+        BigDecimal other  = BigDecimal.ZERO;
+
+        if(CollectionUtils.isNotEmpty(list)){
+            for(AccountRequestFundsDetailVo c:list){
+                switch (c.getCostType()){
+                    case "1"://拖车费
+                        trailerFee = trailerFee.add(c.getAmount().multiply(currencyRatesMap.getOrDefault(c.getCurrency(),BigDecimal.ONE)));
+                        break;
+                    case "2"://报关费
+                        customsFee = customsFee.add(c.getAmount().multiply(currencyRatesMap.getOrDefault(c.getCurrency(),BigDecimal.ONE)));
+                        break;
+                    case "3"://港杂费
+                        portMixedFee = portMixedFee.add(c.getAmount().multiply(currencyRatesMap.getOrDefault(c.getCurrency(),BigDecimal.ONE)));
+                        break;
+                    case "4"://验收红包
+                        inspectionRedPack = inspectionRedPack.add(c.getAmount().multiply(currencyRatesMap.getOrDefault(c.getCurrency(),BigDecimal.ONE)));
+                        break;
+                    case "5"://佣金
+                        commission = commission.add(c.getAmount().multiply(currencyRatesMap.getOrDefault(c.getCurrency(),BigDecimal.ONE)));
+                        break;
+                    case "6"://检测费
+                        checkout = checkout.add(c.getAmount().multiply(currencyRatesMap.getOrDefault(c.getCurrency(),BigDecimal.ONE)));
+                        break;
+                    case "7"://验货费
+                        inspectionCharge = inspectionCharge.add(c.getAmount().multiply(currencyRatesMap.getOrDefault(c.getCurrency(),BigDecimal.ONE)));
+                        break;
+                    case "8"://运费
+                        freight = freight.add(c.getAmount().multiply(currencyRatesMap.getOrDefault(c.getCurrency(),BigDecimal.ONE)));
+                        break;
+                    case "9"://产地证费
+                        certificateOfOrigin = certificateOfOrigin.add(c.getAmount().multiply(currencyRatesMap.getOrDefault(c.getCurrency(),BigDecimal.ONE)));
+                        break;
+                    default:
+                        other = other.add(c.getAmount().multiply(currencyRatesMap.getOrDefault(c.getCurrency(),BigDecimal.ONE)));
+                        break;
+                }
+            }
+        }
+        v.setTrailerFee(trailerFee);
+        v.setCustomsFee(customsFee);
+        v.setPortMixedFee(portMixedFee);
+        v.setInspectionRedPack(inspectionRedPack);
+        v.setCommission(commission);
+        v.setCheckout(checkout);
+        v.setInspectionCharge(inspectionCharge);
+        v.setFreight(freight);
+        v.setCertificateOfOrigin(certificateOfOrigin);
+        v.setOther(other);
+    }
 }

+ 2 - 1
hx-sale/src/main/resources/mapper/contract/ContractMapper.xml

@@ -12,7 +12,8 @@
 
     <select id="getProfitClearingPage" resultType="com.fjhx.sale.entity.contract.vo.ContractBudgetVo">
         SELECT
-            t1.*,
+            t1.id AS contractId,
+            t1.*
         FROM
             contract t1
             ${ew.customSqlSegment}