caozj пре 2 година
родитељ
комит
68eac5a50a

+ 5 - 0
hx-account/src/main/java/com/fjhx/account/entity/account/po/AccountRequestFundsDetail.java

@@ -39,4 +39,9 @@ public class AccountRequestFundsDetail extends BasePo {
      */
     private String remarks;
 
+    /**
+     * 合同ID
+     */
+    private Long contractId;
+
 }

+ 5 - 0
hx-sale/src/main/java/com/fjhx/sale/entity/claim/po/ClaimContract.java

@@ -39,4 +39,9 @@ public class ClaimContract extends BasePo {
      */
     private String contractCode;
 
+    /**
+     * 币种
+     */
+    private String currency;
+
 }

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

@@ -132,4 +132,19 @@ public class ContractBudgetVo extends Contract {
      * 应退税金额
      */
     private BigDecimal RefundableAmount;
+
+    /**
+     * 人民币合同金额
+     */
+    private BigDecimal rmbContractAmount;
+
+    /**
+     * 到账金额
+     */
+    private BigDecimal sumClaimMoney;
+
+    /**
+     * 采购合同总金额
+     */
+    private BigDecimal sumPurchaseContractMoney;
 }

+ 5 - 0
hx-sale/src/main/java/com/fjhx/sale/entity/contract/vo/ContractVo.java

@@ -104,5 +104,10 @@ public class ContractVo extends Contract {
      */
     private String  tag;
 
+    /**
+     * 客户名称
+     */
+    private String customerName;
+
 }
 

+ 5 - 0
hx-sale/src/main/java/com/fjhx/sale/entity/purchase/vo/EhsdPurchaseProductVo.java

@@ -23,4 +23,9 @@ public class EhsdPurchaseProductVo extends EhsdPurchaseProduct {
      * 金额-货品
      */
     private String currencyAmount;
+
+    /**
+     * 币种
+     */
+    private String currency;
 }

+ 5 - 0
hx-sale/src/main/java/com/fjhx/sale/mapper/contract/ContractMapper.java

@@ -38,6 +38,11 @@ public interface ContractMapper extends BaseMapper<Contract> {
     Page<ContractBudgetVo> getProfitBudgetPage(@Param("page") Page<Object> page, @Param("ew") IWrapper<Contract> wrapper);
 
     /**
+     * 利润结算表
+     */
+    Page<ContractBudgetVo> getProfitClearingPage(@Param("page") Page<Object> page, @Param("ew") IWrapper<Contract> wrapper);
+
+    /**
      * 根据客户ID查询未包装的订单
      * @param customerId
      * @return

+ 7 - 0
hx-sale/src/main/java/com/fjhx/sale/mapper/purchase/EhsdPurchaseProductMapper.java

@@ -33,4 +33,11 @@ public interface EhsdPurchaseProductMapper extends BaseMapper<EhsdPurchaseProduc
      * @return
      */
     List<EhsdPurchaseProductVo> getGroupSumAmount(List<Long> contractIds);
+
+    /**
+     * 根据合同ID查询采购产品列表
+     * @param contractId
+     * @return
+     */
+    List<EhsdPurchaseProductVo> getListByContractId(Long contractId);
 }

+ 1 - 1
hx-sale/src/main/java/com/fjhx/sale/service/claim/impl/ClaimServiceImpl.java

@@ -70,7 +70,7 @@ public class ClaimServiceImpl extends ServiceImpl<ClaimMapper, Claim> implements
     @DSTransactional
     public synchronized void add(Claim claim) {
 //        Claim data = this.getOne(Wrappers.<Claim>query().lambda().eq(Claim::getBusinessId,claim.getBusinessId()));
-        if(ObjectUtils.isNotEmpty(claim.getBusinessId())){
+        if(ObjectUtils.isEmpty(claim.getBusinessId())){
             throw new ServiceException("请选择认领数据");
         }
         if(ObjectUtils.isEmpty(claim.getAmount())){

+ 6 - 1
hx-sale/src/main/java/com/fjhx/sale/service/contract/ContractService.java

@@ -36,11 +36,16 @@ public interface ContractService extends BaseService<Contract> {
     Page<ContractVo> getPage(ContractSelectDto dto);
 
     /**
-     * 外销合同表分页
+     * 利润预算分页
      */
     Page<ContractBudgetVo> getProfitBudgetPage(ContractSelectDto dto);
 
     /**
+     * 利润结算分页
+     */
+    Page<ContractBudgetVo> getProfitClearingPage(ContractSelectDto dto);
+
+    /**
      * 外销合同表明细
      */
     ContractVo detail(Long id);

+ 122 - 23
hx-sale/src/main/java/com/fjhx/sale/service/contract/impl/ContractServiceImpl.java

@@ -28,10 +28,13 @@ import com.fjhx.common.service.documentary.GetDocumentaryBusinessTemplate;
 import com.fjhx.customer.entity.customer.dto.CustomerDto;
 import com.fjhx.customer.entity.customer.po.Customer;
 import com.fjhx.customer.service.customer.CustomerService;
+import com.fjhx.sale.entity.claim.po.Claim;
+import com.fjhx.sale.entity.claim.po.ClaimContract;
 import com.fjhx.sale.entity.contract.bo.ContractCurrencyRate;
 import com.fjhx.sale.entity.purchase.po.EhsdPurchaseProduct;
 import com.fjhx.sale.entity.purchase.vo.EhsdPurchaseProductVo;
 import com.fjhx.sale.entity.serviceContract.po.ServiceContract;
+import com.fjhx.sale.service.claim.ClaimContractService;
 import com.fjhx.sale.service.purchase.EhsdPurchaseProductService;
 import com.fjhx.file.entity.FileInfoVo;
 import com.fjhx.file.utils.ObsFileUtil;
@@ -118,6 +121,8 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
     @Autowired
     private CurrencyRateService currencyRateService;
 
+    @Autowired
+    private ClaimContractService claimContractService;
 
     /**
      * 分页
@@ -213,35 +218,25 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
             Map<Long,String> ehsdAmountMap = ehsdAmountList.stream().collect(Collectors.toMap(EhsdPurchaseProductVo::getContractId,EhsdPurchaseProductVo::getCurrencyAmount));
             List<PurchaseDetailVo> otherAmountList = purchaseDetailService.getSumCountInDataResourceIds(contractIds);
             Map<Long,String> otherAmountMap = otherAmountList.stream().collect(Collectors.toMap(PurchaseDetailVo::getDataResourceId,PurchaseDetailVo::getSumAmountCurrency));
+            //取出默认汇率
             List<CurrencyRate> currencyRateList = currencyRateService.getList();
             Map<String,BigDecimal> currencyRateMap = currencyRateList.stream().collect(Collectors.toMap(CurrencyRate::getType,CurrencyRate::getRate));
             for(ContractBudgetVo v : list){
-                v.setRefundableAmount(BigDecimal.ZERO);//暂时先设置退税金额为0
-                if(MapUtils.isNotEmpty(ehsdAmountMap)){    //计算EHSD租户应付货款
-                    String concatAmountCurrency = ehsdAmountMap.getOrDefault(v.getContractId(),null);
-                    if(StringUtils.isNotEmpty(concatAmountCurrency)){
-                        BigDecimal amount = new BigDecimal(concatAmountCurrency.split("-")[0]);
-                        String currency = concatAmountCurrency.split("-")[1];
-                        BigDecimal rate = currencyRateMap.getOrDefault(currency,BigDecimal.ONE);
-                        v.setEhsdSumAmount(amount.multiply(rate));
-                    }else{
-                        v.setEhsdSumAmount(BigDecimal.ZERO);
-                    }
-                }
-                if(MapUtils.isNotEmpty(otherAmountMap)){  //计算其他租户应付货款
-                    String concatAmountCurrency = otherAmountMap.getOrDefault(v.getContractId(),null);
-                    if(StringUtils.isNotEmpty(concatAmountCurrency)){
-                        BigDecimal amount = new BigDecimal(concatAmountCurrency.split("-")[0]);
-                        String currency = concatAmountCurrency.split("-")[1];
-                        BigDecimal rate = currencyRateMap.getOrDefault(currency,BigDecimal.ONE);
-                        v.setOtherSumAmount(amount.multiply(rate));
-                    }else{
-                        v.setOtherSumAmount(BigDecimal.ZERO);
-                    }
-                }
                 if(StringUtils.isNotEmpty(v.getCurrencyRateJson())){//如果此条合同有汇率了
                     List<ContractCurrencyRate> contractCurrencyRates = JSON.parseArray(v.getCurrencyRateJson(), ContractCurrencyRate.class);
                     Map<String,BigDecimal> map = contractCurrencyRates.stream().collect(Collectors.toMap(ContractCurrencyRate::getType,ContractCurrencyRate::getRate));
+                    v.setRefundableAmount(BigDecimal.ZERO);//暂时先设置退税金额为0
+                    if(MapUtils.isNotEmpty(ehsdAmountMap)){    //计算EHSD租户应付货款
+                        String concatAmountCurrency = ehsdAmountMap.getOrDefault(v.getContractId(),null);
+                        if(StringUtils.isNotEmpty(concatAmountCurrency)){
+                            BigDecimal amount = new BigDecimal(concatAmountCurrency.split("-")[0]);
+                            String currency = concatAmountCurrency.split("-")[1];
+                            BigDecimal rate = map.getOrDefault(currency,BigDecimal.ONE);
+                            v.setEhsdSumAmount(amount.multiply(rate));
+                        }else{
+                            v.setEhsdSumAmount(BigDecimal.ZERO);
+                        }
+                    }
                     //计算收入总计=合同金额(转人民币)+应退税金额(转人民币)
                     v.setIncomeAmount(v.getAmount().multiply(new BigDecimal(map.getOrDefault(v.getCurrency(), BigDecimal.ONE).toString())).add(v.getRefundableAmount()));
                     //计算支出总计 除合同金额(转人民币)+应退税金额(转人民币) 其他金额相加
@@ -255,6 +250,18 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
                             (v.getEhsdSumAmount()==null?BigDecimal.ZERO:v.getEhsdSumAmount()).add
                             (v.getOtherSumAmount()==null?BigDecimal.ZERO:v.getOtherSumAmount()));
                 }else{//没有汇率取默认汇率
+                    v.setRefundableAmount(BigDecimal.ZERO);//暂时先设置退税金额为0
+                    if(MapUtils.isNotEmpty(ehsdAmountMap)){    //计算EHSD租户应付货款
+                        String concatAmountCurrency = ehsdAmountMap.getOrDefault(v.getContractId(),null);
+                        if(StringUtils.isNotEmpty(concatAmountCurrency)){
+                            BigDecimal amount = new BigDecimal(concatAmountCurrency.split("-")[0]);
+                            String currency = concatAmountCurrency.split("-")[1];
+                            BigDecimal rate = currencyRateMap.getOrDefault(currency,BigDecimal.ONE);
+                            v.setEhsdSumAmount(amount.multiply(rate));
+                        }else{
+                            v.setEhsdSumAmount(BigDecimal.ZERO);
+                        }
+                    }
                     //计算收入总计=合同金额(转人民币)+应退税金额(转人民币)
                     v.setIncomeAmount(v.getAmount().multiply(currencyRateMap.getOrDefault(v.getContractId(),new BigDecimal("1"))).add(v.getRefundableAmount()));
                     //计算支出总计 除合同金额(转人民币)+应退税金额(转人民币) 其他金额相加
@@ -277,6 +284,60 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
         return page;
     }
 
+    /**
+     * 利润结算表分页
+     * @param dto
+     * @return
+     */
+    @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);
+        if(StringUtils.isNotEmpty(dto.getCustomerId())){
+            wrapper.eq("t1",Contract::getBuyCorporationId,dto.getCustomerId());
+        }
+        if(StringUtils.isNotEmpty(dto.getUserId())){
+            wrapper.eq("t1",Contract::getCreateUser,dto.getUserId());
+        }
+        if(StringUtils.isNotEmpty(dto.getKeyword())){
+            wrapper.keyword(dto.getKeyword(),new SqlField("t1.code"));
+        }
+        Page<ContractBudgetVo> page = this.baseMapper.getProfitClearingPage(dto.getPage(), wrapper);
+        List<ContractBudgetVo> list = page.getRecords();
+        //取出默认汇率
+        List<CurrencyRate> defaultCurrencyRateList = currencyRateService.getList();
+        Map<String,BigDecimal> defaultCurrencyRateMap = defaultCurrencyRateList.stream().collect(Collectors.toMap(CurrencyRate::getType,CurrencyRate::getRate));
+        for(ContractBudgetVo v : list){
+            v.setRefundableAmount(BigDecimal.ZERO);//暂时先设置退税金额为0
+            // 赋值客户名称
+            customerService.attributeAssign(list, Contract::getBuyCorporationId, (item, customer) -> {
+                item.setCustomerName(customer.getName());
+            });
+            if(StringUtils.isNotEmpty(v.getCurrencyRateJson())) {//如果此条合同有汇率了
+                //取出汇率
+                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.setSumClaimMoney(this.getSumClaimMoney(v,assignCurrencyRatesMap));
+                //采购合同总金额
+                v.setSumPurchaseContractMoney(this.getSumPurchaseContractMoney(v,assignCurrencyRatesMap));
+            }else{//没有取默认的汇率
+                v.setEhsdSumAmount(v.getAmount().multiply(defaultCurrencyRateMap.getOrDefault(v.getCurrency(),BigDecimal.ONE)));//计算汇算人民币
+                //到账金额
+                v.setSumClaimMoney(this.getSumClaimMoney(v,defaultCurrencyRateMap));
+                //采购合同总金额
+                v.setSumPurchaseContractMoney(this.getSumPurchaseContractMoney(v,defaultCurrencyRateMap));
+            }
+
+        }
+        return page;
+    }
+
     @Override
     public ContractVo detail(Long id) {
         Contract Contract = this.getById(id);
@@ -889,4 +950,42 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
 
     }
 
+    /**
+     * 统计到账认领总金额
+     * @param v
+     * @param currencyRatesMap 汇率JSON
+     * @return
+     */
+    private BigDecimal getSumClaimMoney(ContractBudgetVo v,Map<String,BigDecimal> currencyRatesMap){
+        List<ClaimContract> claimContractList = claimContractService.list(Wrappers.<ClaimContract>query().lambda().eq(ClaimContract::getContractId,v.getContractId()));
+        BigDecimal sumClaimMOney = BigDecimal.ZERO;
+        if(CollectionUtils.isNotEmpty(claimContractList)){
+            for(ClaimContract c:claimContractList){
+                sumClaimMOney.add(c.getMoney().multiply(currencyRatesMap.getOrDefault(c.getCurrency(),BigDecimal.ONE)));
+            }
+            return sumClaimMOney;
+        }else{
+            return BigDecimal.ZERO;
+        }
+    }
+
+    /**
+     * 统采购合同总金额
+     * @param v
+     * @param currencyRatesMap 汇率JSON
+     * @return
+     */
+    private BigDecimal getSumPurchaseContractMoney(ContractBudgetVo v,Map<String,BigDecimal> currencyRatesMap){
+        List<EhsdPurchaseProductVo> list = ehsdPurchaseProductService.getListByContractId(v.getContractId());
+        BigDecimal sumPurchaseContractMoney = BigDecimal.ZERO;
+        if(CollectionUtils.isNotEmpty(list)){
+            for(EhsdPurchaseProductVo c:list){
+                sumPurchaseContractMoney.add(c.getAmount().multiply(currencyRatesMap.getOrDefault(c.getCurrency(),BigDecimal.ONE)));
+            }
+            return sumPurchaseContractMoney;
+        }else{
+            return BigDecimal.ZERO;
+        }
+    }
+
 }

+ 8 - 0
hx-sale/src/main/java/com/fjhx/sale/service/purchase/EhsdPurchaseProductService.java

@@ -53,4 +53,12 @@ public interface EhsdPurchaseProductService extends BaseService<EhsdPurchaseProd
      * @return
      */
     List<EhsdPurchaseProductVo> getGroupSumAmount(List<Long> contractIds);
+
+    /**
+     * 根据合同ID查询采购产品列表
+     * @param contractId
+     * @return
+     */
+    List<EhsdPurchaseProductVo> getListByContractId(Long contractId);
+
 }

+ 10 - 0
hx-sale/src/main/java/com/fjhx/sale/service/purchase/impl/EhsdPurchaseProductServiceImpl.java

@@ -68,5 +68,15 @@ public class EhsdPurchaseProductServiceImpl extends ServiceImpl<EhsdPurchaseProd
         return baseMapper.getGroupSumAmount(contractIds);
     }
 
+    /**
+     * 根据合同ID查询采购产品列表
+     * @param contractId
+     * @return
+     */
+    @Override
+    public List<EhsdPurchaseProductVo> getListByContractId(Long contractId) {
+        return baseMapper.getListByContractId(contractId);
+    }
+
 
 }

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

@@ -10,10 +10,9 @@
             ${ew.customSqlSegment}
     </select>
 
-    <select id="getProfitClearingPage" resultType="com.fjhx.sale.entity.contract.vo.ContractVo">
+    <select id="getProfitClearingPage" resultType="com.fjhx.sale.entity.contract.vo.ContractBudgetVo">
         SELECT
             t1.*,
-            (select SUM(money) from claim_contract WHERE contract_id = t1.id) AS sumClaimMoney
         FROM
             contract t1
             ${ew.customSqlSegment}

+ 11 - 0
hx-sale/src/main/resources/mapper/purchase/EhsdPurchaseProductMapper.xml

@@ -38,4 +38,15 @@
         </if>
         GROUP BY t1.contract_id
     </select>
+
+    <select id="getListByContractId" resultType="com.fjhx.sale.entity.purchase.vo.EhsdPurchaseProductVo">
+        SELECT
+            t1.*,
+            t2.currency
+        FROM
+            ehsd_purchase_product t1
+                LEFT JOIN ehsd_purchase t2 ON t1.purchase_id = t2.id
+        WHERE
+            t1.contract_id = #{contractId}
+    </select>
 </mapper>