Browse Source

利润预算表修复

caozj 1 year ago
parent
commit
7e2c1118d7

+ 16 - 0
hx-account/src/main/resources/mapper/tax/TaxRefundDetailsMapper.xml

@@ -24,4 +24,20 @@
         LEFT JOIN account_running_water t2 ON t1.account_running_water_id = t2.id
             ${ew.customSqlSegment}
     </select>
+
+    <select id="getSumAmountByContractId" resultType="com.fjhx.account.entity.tax.po.TaxRefundDetails">
+        SELECT
+            IFNULL( SUM( t1.amount * t2.rate ), 0 ) AS amount,
+            t1.contract_id AS contractId
+        FROM
+            tax_refund_details t1
+        LEFT JOIN account_running_water t2 ON t1.account_running_water_id = t2.id
+        <if test="contractIds neq null and contractIds.size() > 0">
+            <foreach collection="contractIds" item="contractId" open="AND t1.contract_id IN (" separator="," close=")">
+                #{contractId}
+            </foreach>
+        </if>
+        GROUP BY
+            t1.contract_id
+    </select>
 </mapper>

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

@@ -279,6 +279,11 @@ public class Contract extends BasePo {
     private String beneficiaryAccountNumber;
 
     /**
+     * 利润预算表金额
+     */
+    private String budgetMoney;
+
+    /**
      * 利润预算表备注
      */
     private String budgetRemark;

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

@@ -4,6 +4,8 @@ import com.fjhx.sale.entity.purchase.po.EhsdPurchaseProduct;
 import lombok.Getter;
 import lombok.Setter;
 
+import java.math.BigDecimal;
+
 /**
  * ehsd采购产品表列表查询返回值实体
  *
@@ -33,4 +35,6 @@ public class EhsdPurchaseProductVo extends EhsdPurchaseProduct {
      * 产品定义
      */
     private Integer definition;
+
+    private BigDecimal rate;
 }

+ 60 - 16
hx-sale/src/main/java/com/fjhx/sale/service/contract/impl/ContractServiceImpl.java

@@ -16,8 +16,10 @@ import com.fjhx.account.controller.utils.DateUtils;
 import com.fjhx.account.entity.account.po.AccountManagement;
 import com.fjhx.account.entity.account.vo.AccountRequestFundsDetailVo;
 import com.fjhx.account.entity.account.vo.AccountRunningWaterVo;
+import com.fjhx.account.entity.tax.po.TaxRefundDetails;
 import com.fjhx.account.service.account.AccountManagementService;
 import com.fjhx.account.service.account.AccountRequestFundsDetailService;
+import com.fjhx.account.service.tax.TaxRefundDetailsService;
 import com.fjhx.area.service.SetCustomizeAreaId;
 import com.fjhx.area.utils.CustomizeAreaUtil;
 import com.fjhx.common.constant.SourceConstant;
@@ -175,6 +177,9 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
     @Autowired
     private ContractTemplateService contractTemplateService;
 
+    @Autowired
+    private TaxRefundDetailsService taxRefundDetailsService;
+
     /**
      * 合同和样品单 下拉分页
      */
@@ -359,6 +364,10 @@ 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));
+            //通过合同ID查询到退税数据
+            List<TaxRefundDetails> refundDetails = taxRefundDetailsService.getSumMoneyByContractIds(contractIds);
+            Map<Long,List<TaxRefundDetails>> refundDetailsMap = refundDetails.stream().collect(Collectors.groupingBy(TaxRefundDetails::getContractId));
+
             //取出默认汇率
 //            List<CurrencyRate> currencyRateList = currencyRateService.getList();
 //            Map<String, BigDecimal> currencyRateMap = currencyRateList.stream().collect(Collectors.toMap(CurrencyRate::getType, CurrencyRate::getRate));
@@ -377,8 +386,6 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
                             v.setEhsdSumAmount(BigDecimal.ZERO);
                         }
                     }
-                    //计算收入总计=合同金额(转人民币)+应退税金额(转人民币)
-                    v.setIncomeAmount(v.getAmount().multiply(new BigDecimal(map.getOrDefault(v.getCurrency(), BigDecimal.ONE).toString())).add(v.getRefundableAmount()));
                     //计算支出总计 除合同金额(转人民币)+应退税金额(转人民币) 其他金额相加
                     v.setExpenditureAmount(v.getTrailerFee() == null ? BigDecimal.ZERO : v.getTrailerFee().multiply(new BigDecimal(map.getOrDefault(v.getTrailerFeeCurrency(), BigDecimal.ONE).toString())).add
                             (v.getCustomsFee() == null ? BigDecimal.ZERO : v.getCustomsFee().multiply(new BigDecimal(map.getOrDefault(v.getCustomsFeeCurrency(), BigDecimal.ONE).toString()))).add
@@ -389,23 +396,38 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
                             (v.getOther() == null ? BigDecimal.ZERO : v.getOther().multiply(new BigDecimal(map.getOrDefault(v.getOtherCurrency(), BigDecimal.ONE).toString()))).add
                             (v.getEhsdSumAmount() == null ? BigDecimal.ZERO : v.getEhsdSumAmount()).add
                             (v.getOtherSumAmount() == null ? BigDecimal.ZERO : v.getOtherSumAmount()));
-                    v.setRefundableAmount(BigDecimal.ZERO);//暂时先设置退税金额为0
+                    /**
+                     * 处理退税金额
+                     */
+                    List<TaxRefundDetails> rList = refundDetailsMap.getOrDefault(v.getContractId(),null);
+                    if(CollectionUtils.isNotEmpty(rList)){
+                        BigDecimal taxReturnMoney = rList.stream().map(taxRefundDetails -> {
+                            //获取汇率
+                            BigDecimal rate = map.getOrDefault(taxRefundDetails.getCurrency(), BigDecimal.ONE);
+                            // 获取认领金额
+                            BigDecimal money = taxRefundDetails.getAmount();
+                            // 返回兑人民币后金额
+                            return rate.multiply(money);
+                        }).reduce(BigDecimal.ZERO, BigDecimal::add);
+                        v.setRefundableAmount(taxReturnMoney);
+                    }
                     v.setRmbContractAmount(v.getAmount().multiply(new BigDecimal(map.getOrDefault(v.getCurrency(), BigDecimal.ONE).toString())));
+                    //计算收入总计=合同金额(转人民币)+应退税金额(转人民币)
+                    v.setIncomeAmount(v.getAmount().multiply(new BigDecimal(map.getOrDefault(v.getCurrency(), BigDecimal.ONE).toString())).add(v.getRefundableAmount()));
                 } else {//没有汇率取默认汇率
-                    BigDecimal rate = v.getRate();
                     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 = v.getRate();
-                            v.setEhsdSumAmount(amount.multiply(rate));
+                            String rate = concatAmountCurrency.split("-")[2];
+                            BigDecimal DecimalRate = new BigDecimal(rate);
+                            v.setEhsdSumAmount(amount.multiply(DecimalRate));
                         } else {
                             v.setEhsdSumAmount(BigDecimal.ZERO);
                         }
                     }
-                    //计算收入总计=合同金额(转人民币)+应退税金额(转人民币)
-                    v.setIncomeAmount(v.getAmount().multiply(rate).add(v.getRefundableAmount()));
+                    BigDecimal rate = v.getRate();
+
                     //计算支出总计 除合同金额(转人民币)+应退税金额(转人民币) 其他金额相加
                     v.setExpenditureAmount(
                             v.getTrailerFee() == null ? BigDecimal.ZERO : v.getTrailerFee().multiply(rate).add
@@ -417,13 +439,29 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
                             (v.getOther() == null ? BigDecimal.ZERO : v.getOther().multiply(rate)).add
                             (v.getEhsdSumAmount() == null ? BigDecimal.ZERO : v.getEhsdSumAmount()).add
                             (v.getOtherSumAmount() == null ? BigDecimal.ZERO : v.getOtherSumAmount()));
-                    v.setRefundableAmount(BigDecimal.ZERO);//暂时先设置退税金额为0
+                    /**
+                     * 处理退税金额
+                     */
+                    List<TaxRefundDetails> rList = refundDetailsMap.getOrDefault(v.getContractId(),null);
+                    if(CollectionUtils.isNotEmpty(rList)){
+                        BigDecimal taxReturnMoney = rList.stream().map(taxRefundDetails -> {
+                            //获取汇率
+                            BigDecimal reRate = taxRefundDetails.getRate();
+                            // 获取认领金额
+                            BigDecimal money = taxRefundDetails.getAmount();
+                            // 返回兑人民币后金额
+                            return reRate.multiply(money);
+                        }).reduce(BigDecimal.ZERO, BigDecimal::add);
+                        v.setRefundableAmount(taxReturnMoney);
+                    }
                     v.setRmbContractAmount(v.getAmount().multiply(rate));
+                    //计算收入总计=合同金额(转人民币)+应退税金额(转人民币)
+                    v.setIncomeAmount(v.getAmount().multiply(rate).add(v.getRefundableAmount()));
                 }
                 //计算毛利 收入-支出
                 v.setGross(v.getIncomeAmount().subtract(v.getExpenditureAmount()));
                 //计算毛利率 毛利/收入
-                v.setGrossRate(v.getGross().divide(v.getIncomeAmount(), RoundingMode.CEILING));
+                v.setGrossRate(v.getGross().divide(v.getIncomeAmount(), RoundingMode.CEILING).multiply(new BigDecimal("100")));
             }
         }
         return page;
@@ -454,6 +492,7 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
         //取出默认汇率
         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
             v.setOtherIncomeAmount(BigDecimal.ZERO);//暂时先设置其他收入为0
@@ -470,7 +509,7 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
                 //到账金额
                 v.setSumClaimMoney(this.getSumClaimMoney(v, assignCurrencyRatesMap));
                 //采购合同总金额
-                v.setSumPurchaseContractMoney(this.getSumPurchaseContractMoney(v, assignCurrencyRatesMap));
+                v.setSumPurchaseContractMoney(this.getSumPurchaseContractMoney(v, assignCurrencyRatesMap,1));
                 //支出费用
                 this.getGroupTypeMoney(v, assignCurrencyRatesMap);
             } else {//没有取默认的汇率
@@ -478,7 +517,7 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
                 //到账金额
                 v.setSumClaimMoney(this.getSumClaimMoney(v, defaultCurrencyRateMap));
                 //采购合同总金额
-                v.setSumPurchaseContractMoney(this.getSumPurchaseContractMoney(v, defaultCurrencyRateMap));
+                v.setSumPurchaseContractMoney(this.getSumPurchaseContractMoney(v, defaultCurrencyRateMap,2));
                 //支出费用
                 this.getGroupTypeMoney(v, defaultCurrencyRateMap);
             }
@@ -500,7 +539,7 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
             //计算毛利 收入-支出
             v.setGross(v.getIncomeAmount().subtract(v.getExpenditureAmount()));
             //计算毛利率 毛利/收入
-            v.setGrossRate(v.getGross().divide(v.getIncomeAmount(), RoundingMode.CEILING));
+            v.setGrossRate(v.getGross().divide(v.getIncomeAmount(), RoundingMode.CEILING).multiply(new BigDecimal("100")));
 
         }
         return page;
@@ -1454,12 +1493,17 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
      * @param currencyRatesMap 汇率JSON
      * @return
      */
-    private BigDecimal getSumPurchaseContractMoney(ContractBudgetVo v, Map<String, BigDecimal> currencyRatesMap) {
+    private BigDecimal getSumPurchaseContractMoney(ContractBudgetVo v, Map<String, BigDecimal> currencyRatesMap,int type) {
         List<EhsdPurchaseProductVo> list = ehsdPurchaseProductService.getListByContractId(v.getContractId());
         BigDecimal sumPurchaseContractMoney = BigDecimal.ZERO;
         if (CollectionUtils.isNotEmpty(list)) {
             for (EhsdPurchaseProductVo c : list) {
-                sumPurchaseContractMoney = sumPurchaseContractMoney.add(c.getAmount().multiply(currencyRatesMap.getOrDefault(c.getCurrency(), BigDecimal.ONE)));
+                if(type==1){
+                    sumPurchaseContractMoney = sumPurchaseContractMoney.add(c.getAmount().multiply(currencyRatesMap.getOrDefault(c.getCurrency(), BigDecimal.ONE)));
+                }else{
+                    sumPurchaseContractMoney = sumPurchaseContractMoney.add(c.getAmount().multiply(c.getRate()));
+                }
+
             }
             return sumPurchaseContractMoney;
         } else {

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

@@ -40,7 +40,9 @@
             t1.amount,
             t1.currency,
             t1.currency_rate_json,
-            t2.*
+            t1.rate AS rate,
+            t2.*,
+            IFNULL(t1.budget_money,0)AS budgetMoney
         FROM
             contract t1
         LEFT JOIN contract_budget t2 ON t1.id = t2.contract_id

+ 10 - 3
hx-sale/src/main/resources/mapper/purchase/EhsdPurchaseProductMapper.xml

@@ -23,13 +23,19 @@
 
     <select id="getGroupSumAmount" resultType="com.fjhx.sale.entity.purchase.vo.EhsdPurchaseProductVo">
         SELECT
-            CONCAT( IFNULL( SUM( t1.amount ), 0 ), "-", IFNULL(t2.currency,"¥") )  AS currencyAmount,
+            CONCAT(
+            IFNULL( SUM( t1.amount )+( SELECT IFNULL( SUM( amount ), 0 ) FROM ehsd_purchase_product_mountings WHERE purchase_product_id = t1.id ), 0 ),
+            "-",
+            IFNULL( t2.currency, "¥" ),
+            "-",
+            IFNULL( t2.rate, 1 )
+            ) AS currencyAmount,
             t1.contract_id AS contractId
         FROM
             ehsd_purchase_product t1
         LEFT JOIN ehsd_purchase t2 ON t1.purchase_id = t2.id
         WHERE
-        t2.`status` &gt;= 30
+        t2.`status` &gt;= 10
         AND t2.`status` &lt; 88
         <if test="contractIds neq null and contractIds.size() > 0">
             <foreach collection="contractIds" item="contractId" open="AND t1.contract_id IN (" separator="," close=")">
@@ -42,7 +48,8 @@
     <select id="getListByContractId" resultType="com.fjhx.sale.entity.purchase.vo.EhsdPurchaseProductVo">
         SELECT
             t1.*,
-            t2.currency
+            t2.currency,
+            t2.rate
         FROM
             ehsd_purchase_product t1
                 LEFT JOIN ehsd_purchase t2 ON t1.purchase_id = t2.id