|
@@ -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.dto.CustomerDto;
|
|
import com.fjhx.customer.entity.customer.po.Customer;
|
|
import com.fjhx.customer.entity.customer.po.Customer;
|
|
import com.fjhx.customer.service.customer.CustomerService;
|
|
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.contract.bo.ContractCurrencyRate;
|
|
import com.fjhx.sale.entity.purchase.po.EhsdPurchaseProduct;
|
|
import com.fjhx.sale.entity.purchase.po.EhsdPurchaseProduct;
|
|
import com.fjhx.sale.entity.purchase.vo.EhsdPurchaseProductVo;
|
|
import com.fjhx.sale.entity.purchase.vo.EhsdPurchaseProductVo;
|
|
import com.fjhx.sale.entity.serviceContract.po.ServiceContract;
|
|
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.sale.service.purchase.EhsdPurchaseProductService;
|
|
import com.fjhx.file.entity.FileInfoVo;
|
|
import com.fjhx.file.entity.FileInfoVo;
|
|
import com.fjhx.file.utils.ObsFileUtil;
|
|
import com.fjhx.file.utils.ObsFileUtil;
|
|
@@ -118,6 +121,8 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
|
|
@Autowired
|
|
@Autowired
|
|
private CurrencyRateService currencyRateService;
|
|
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));
|
|
Map<Long,String> ehsdAmountMap = ehsdAmountList.stream().collect(Collectors.toMap(EhsdPurchaseProductVo::getContractId,EhsdPurchaseProductVo::getCurrencyAmount));
|
|
List<PurchaseDetailVo> otherAmountList = purchaseDetailService.getSumCountInDataResourceIds(contractIds);
|
|
List<PurchaseDetailVo> otherAmountList = purchaseDetailService.getSumCountInDataResourceIds(contractIds);
|
|
Map<Long,String> otherAmountMap = otherAmountList.stream().collect(Collectors.toMap(PurchaseDetailVo::getDataResourceId,PurchaseDetailVo::getSumAmountCurrency));
|
|
Map<Long,String> otherAmountMap = otherAmountList.stream().collect(Collectors.toMap(PurchaseDetailVo::getDataResourceId,PurchaseDetailVo::getSumAmountCurrency));
|
|
|
|
+ //取出默认汇率
|
|
List<CurrencyRate> currencyRateList = currencyRateService.getList();
|
|
List<CurrencyRate> currencyRateList = currencyRateService.getList();
|
|
Map<String,BigDecimal> currencyRateMap = currencyRateList.stream().collect(Collectors.toMap(CurrencyRate::getType,CurrencyRate::getRate));
|
|
Map<String,BigDecimal> currencyRateMap = currencyRateList.stream().collect(Collectors.toMap(CurrencyRate::getType,CurrencyRate::getRate));
|
|
for(ContractBudgetVo v : list){
|
|
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())){//如果此条合同有汇率了
|
|
if(StringUtils.isNotEmpty(v.getCurrencyRateJson())){//如果此条合同有汇率了
|
|
List<ContractCurrencyRate> contractCurrencyRates = JSON.parseArray(v.getCurrencyRateJson(), ContractCurrencyRate.class);
|
|
List<ContractCurrencyRate> contractCurrencyRates = JSON.parseArray(v.getCurrencyRateJson(), ContractCurrencyRate.class);
|
|
Map<String,BigDecimal> map = contractCurrencyRates.stream().collect(Collectors.toMap(ContractCurrencyRate::getType,ContractCurrencyRate::getRate));
|
|
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()));
|
|
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.getEhsdSumAmount()==null?BigDecimal.ZERO:v.getEhsdSumAmount()).add
|
|
(v.getOtherSumAmount()==null?BigDecimal.ZERO:v.getOtherSumAmount()));
|
|
(v.getOtherSumAmount()==null?BigDecimal.ZERO:v.getOtherSumAmount()));
|
|
}else{//没有汇率取默认汇率
|
|
}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()));
|
|
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;
|
|
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
|
|
@Override
|
|
public ContractVo detail(Long id) {
|
|
public ContractVo detail(Long id) {
|
|
Contract Contract = this.getById(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;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|