|
@@ -3,6 +3,7 @@ package com.fjhx.sale.service.contract.impl;
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.alibaba.fastjson2.JSON;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
@@ -16,22 +17,29 @@ import com.fjhx.account.service.account.AccountManagementService;
|
|
|
import com.fjhx.area.service.SetCustomizeAreaId;
|
|
|
import com.fjhx.area.utils.CustomizeAreaUtil;
|
|
|
import com.fjhx.common.entity.corporation.po.Corporation;
|
|
|
+import com.fjhx.common.entity.currency.po.CurrencyRate;
|
|
|
import com.fjhx.common.entity.documentary.bo.DocumentaryData;
|
|
|
import com.fjhx.common.enums.FlowStatusEnum;
|
|
|
import com.fjhx.common.service.corporation.CorporationService;
|
|
|
+import com.fjhx.common.service.currency.CurrencyRateService;
|
|
|
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.ehsd.entity.purchase.po.EhsdPurchaseProduct;
|
|
|
+import com.fjhx.ehsd.service.purchase.EhsdPurchaseProductService;
|
|
|
import com.fjhx.file.entity.FileInfoVo;
|
|
|
import com.fjhx.file.utils.ObsFileUtil;
|
|
|
import com.fjhx.item.entity.product.dto.ProductInfoSelectDto;
|
|
|
import com.fjhx.item.service.product.ProductInfoService;
|
|
|
+import com.fjhx.purchase.entity.purchase.vo.PurchaseDetailVo;
|
|
|
+import com.fjhx.purchase.service.purchase.PurchaseDetailService;
|
|
|
import com.fjhx.sale.entity.contract.bo.ContractDocumentaryBo;
|
|
|
import com.fjhx.sale.entity.contract.dto.ContractDto;
|
|
|
import com.fjhx.sale.entity.contract.dto.ContractSelectDto;
|
|
|
import com.fjhx.sale.entity.contract.po.Contract;
|
|
|
import com.fjhx.sale.entity.contract.po.ContractProduct;
|
|
|
+import com.fjhx.sale.entity.contract.vo.ContractBudgetVo;
|
|
|
import com.fjhx.sale.entity.contract.vo.ContractDocumentaryVo;
|
|
|
import com.fjhx.sale.entity.contract.vo.ContractPdfInfoVo;
|
|
|
import com.fjhx.sale.entity.contract.vo.ContractVo;
|
|
@@ -42,6 +50,7 @@ import com.fjhx.sale.service.contract.ContractService;
|
|
|
import com.ruoyi.common.core.domain.BaseSelectDto;
|
|
|
import com.ruoyi.common.exception.ServiceException;
|
|
|
import com.ruoyi.common.utils.PageUtils;
|
|
|
+import com.ruoyi.common.utils.SecurityUtils;
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
|
import com.ruoyi.common.utils.wrapper.IWrapper;
|
|
|
import com.ruoyi.common.utils.wrapper.SqlField;
|
|
@@ -54,6 +63,7 @@ import org.springframework.security.core.context.SecurityContextHolder;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
@@ -94,6 +104,15 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
|
|
|
@Autowired
|
|
|
private AccountManagementService accountManagementService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private EhsdPurchaseProductService ehsdPurchaseProductService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PurchaseDetailService purchaseDetailService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CurrencyRateService currencyRateService;
|
|
|
+
|
|
|
/**
|
|
|
* 分页
|
|
|
*
|
|
@@ -152,6 +171,73 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
|
|
|
return page;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 利润预算
|
|
|
+ * @param dto
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @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);
|
|
|
+ Page<ContractBudgetVo> page = this.baseMapper.getProfitBudgetPage(dto.getPage(), wrapper);
|
|
|
+ List<ContractBudgetVo> list = page.getRecords();
|
|
|
+ if(CollectionUtils.isNotEmpty(list)){
|
|
|
+ List<Long> contractIds = list.stream().map(ContractBudgetVo::getContractId).collect(Collectors.toList());
|
|
|
+ Map<Long,BigDecimal> ehsdAmountMap = ehsdPurchaseProductService.getGroupSumAmount(contractIds);
|
|
|
+ List<PurchaseDetailVo> otherAmountList = purchaseDetailService.getSumCountInDataResourceIds(contractIds);
|
|
|
+ Map<Long,BigDecimal> otherAmountMap = otherAmountList.stream().collect(Collectors.toMap(PurchaseDetailVo::getDataResourceId,PurchaseDetailVo::getSumCount));
|
|
|
+ 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);//先设置退税金额
|
|
|
+ if(MapUtils.isNotEmpty(ehsdAmountMap)){ //计算EHSD租户应付货款
|
|
|
+ v.setEhsdSumAmount(ehsdAmountMap.getOrDefault(v.getContractId(),null));
|
|
|
+ }
|
|
|
+ if(MapUtils.isNotEmpty(otherAmountMap)){ //计算其他租户应付货款
|
|
|
+ v.setOtherumAmount(otherAmountMap.getOrDefault(v.getContractId(),null));
|
|
|
+ }
|
|
|
+ if(StringUtils.isNotEmpty(v.getCurrencyRateJson())){//如果此条合同有汇率了
|
|
|
+ Map<String,Object> map = JSON.parseObject(v.getCurrencyRateJson());
|
|
|
+ //计算收入总计=合同金额(转人民币)+应退税金额(转人民币)
|
|
|
+ v.setIncomeAmount(v.getAmount().multiply(new BigDecimal(map.getOrDefault(v.getCurrency(), BigDecimal.ONE).toString())).add(v.getRefundableAmount()));
|
|
|
+ //计算支出总计 除合同金额(转人民币)+应退税金额(转人民币) 其他金额相加
|
|
|
+ v.setExpenditureAmount(v.getTrailerFee().multiply(new BigDecimal(map.getOrDefault(v.getTrailerFeeCurrency(),BigDecimal.ONE).toString())).add
|
|
|
+ (v.getCustomsFee().multiply(new BigDecimal(map.getOrDefault(v.getCustomsFeeCurrency(),BigDecimal.ONE).toString()))).add
|
|
|
+ (v.getAgencyFee().multiply(new BigDecimal(map.getOrDefault(v.getAgencyFeeCurrency(),BigDecimal.ONE).toString()))).add
|
|
|
+ (v.getPortMixedFee().multiply(new BigDecimal(map.getOrDefault(v.getPortMixedFeeCurrency(),BigDecimal.ONE).toString()))).add
|
|
|
+ (v.getInspectionRedPack().multiply(new BigDecimal(map.getOrDefault(v.getInspectionRedPackCurrency(),BigDecimal.ONE).toString()))).add
|
|
|
+ (v.getCommission().multiply(new BigDecimal(map.getOrDefault(v.getCommissionCurrency(),BigDecimal.ONE).toString()))).add
|
|
|
+ (v.getOther().multiply(new BigDecimal(map.getOrDefault(v.getOtherCurrency(),BigDecimal.ONE).toString()))).add
|
|
|
+ (v.getEhsdSumAmount()).add
|
|
|
+ (v.getOtherumAmount()));
|
|
|
+ }else{//没有汇率取默认汇率
|
|
|
+ //计算收入总计=合同金额(转人民币)+应退税金额(转人民币)
|
|
|
+ v.setIncomeAmount(v.getAmount().multiply(currencyRateMap.getOrDefault(v.getContractId(),new BigDecimal("1"))).add(v.getRefundableAmount()));
|
|
|
+ //计算支出总计 除合同金额(转人民币)+应退税金额(转人民币) 其他金额相加
|
|
|
+ v.setExpenditureAmount(v.getTrailerFee().multiply(new BigDecimal(currencyRateMap.getOrDefault(v.getTrailerFeeCurrency(),BigDecimal.ONE).toString())).add
|
|
|
+ (v.getCustomsFee().multiply(new BigDecimal(currencyRateMap.getOrDefault(v.getCustomsFeeCurrency(),BigDecimal.ONE).toString()))).add
|
|
|
+ (v.getAgencyFee().multiply(new BigDecimal(currencyRateMap.getOrDefault(v.getAgencyFeeCurrency(),BigDecimal.ONE).toString()))).add
|
|
|
+ (v.getPortMixedFee().multiply(new BigDecimal(currencyRateMap.getOrDefault(v.getPortMixedFeeCurrency(),BigDecimal.ONE).toString()))).add
|
|
|
+ (v.getInspectionRedPack().multiply(new BigDecimal(currencyRateMap.getOrDefault(v.getInspectionRedPackCurrency(),BigDecimal.ONE).toString()))).add
|
|
|
+ (v.getCommission().multiply(new BigDecimal(currencyRateMap.getOrDefault(v.getCommissionCurrency(),BigDecimal.ONE).toString()))).add
|
|
|
+ (v.getOther().multiply(new BigDecimal(currencyRateMap.getOrDefault(v.getOtherCurrency(),BigDecimal.ONE).toString()))).add
|
|
|
+ (v.getEhsdSumAmount()).add
|
|
|
+ (v.getOtherumAmount()));
|
|
|
+ }
|
|
|
+ //计算毛利 收入-支出
|
|
|
+ v.setGross(v.getExpenditureAmount().subtract(v.getIncomeAmount()));
|
|
|
+ //计算毛利率 毛利/收入
|
|
|
+ v.setGrossRate(v.getGross().divide(v.getIncomeAmount(), RoundingMode.CEILING));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public ContractVo detail(Long id) {
|
|
|
Contract Contract = this.getById(id);
|