Ver Fonte

合同EHSD

caozj há 2 anos atrás
pai
commit
db02b828c6

+ 8 - 0
hx-common/src/main/java/com/fjhx/common/enums/CodingRuleEnum.java

@@ -26,6 +26,14 @@ public enum CodingRuleEnum {
             getDefaultRule(RuleTypeEnum.CUSTOMER_CODE),
             getDefaultRule(RuleTypeEnum.AUTOINCREMENT, "5")
     )),
+    /**
+     * 外销合同
+     */
+    CONTRACT("contract", "外销合同", Arrays.asList(
+            getDefaultRule(RuleTypeEnum.CUSTOMIZE, "SC-"),
+            getDefaultRule(RuleTypeEnum.DATE_FORMAT, "yyyyMM"),
+            getDefaultRule(RuleTypeEnum.AUTOINCREMENT, "3")
+    )),
 
     ;
 

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

@@ -41,6 +41,11 @@ public class PurchaseDetailVo extends PurchaseDetail {
     private BigDecimal sumAmount;
 
     /**
+     * 总采购金额-货币
+     */
+    private String sumAmountCurrency;
+
+    /**
      * 产品定义
      */
     private Integer productDefinition;

+ 1 - 0
hx-purchase/src/main/resources/mapper/purchase/PurchaseDetailMapper.xml

@@ -40,6 +40,7 @@
         SELECT
             sum( t1.count ) AS sumCount,
             sum( t1.amount ) AS sumAmount,
+            CONCAT( IFNULL( SUM( t1.amount ), 0 ), "-", IFNULL(t2.currency,"¥") ) AS sumAmountCurrency,
             t1.data_resource_id
         FROM
             purchase_detail t1

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

@@ -33,6 +33,11 @@ public class ContractProductVo extends ContractProduct {
     private String contractVersion;
 
     /**
+     * 产品型号
+     */
+    private String productModel;
+
+    /**
      * 转生产数量
      */
     private BigDecimal productQuantity;

+ 26 - 21
hx-sale/src/main/java/com/fjhx/sale/entity/purchase/po/EhsdPurchase.java

@@ -51,32 +51,17 @@ public class EhsdPurchase extends BasePo {
     /**
      * 卖方国家表id
      */
-    private String sellCountryId;
+    private Long sellCountryId;
 
     /**
      * 卖方省份id
      */
-    private String sellProvinceId;
+    private Long sellProvinceId;
 
     /**
      * 卖方城市id
      */
-    private String sellCityId;
-
-    /**
-     * 卖方国家表名称
-     */
-    private String sellCountryName;
-
-    /**
-     * 卖方省份名称
-     */
-    private String sellProvinceName;
-
-    /**
-     * 卖方城市名称
-     */
-    private String sellCityName;
+    private Long sellCityId;
 
     /**
      * 卖方详细地址
@@ -101,17 +86,32 @@ public class EhsdPurchase extends BasePo {
     /**
      * 买方国家表id
      */
-    private Long buyCountryId;
+    private String buyCountryId;
 
     /**
      * 买方省份id
      */
-    private Long buyProvinceId;
+    private String buyProvinceId;
 
     /**
      * 买方城市id
      */
-    private Long buyCityId;
+    private String buyCityId;
+
+    /**
+     * 买方国家表名称
+     */
+    private String buyCountryName;
+
+    /**
+     * 买方省份名称
+     */
+    private String buyProvinceName;
+
+    /**
+     * 买方城市名称
+     */
+    private String buyCityName;
 
     /**
      * 买方详细地址
@@ -139,6 +139,11 @@ public class EhsdPurchase extends BasePo {
     private BigDecimal amount;
 
     /**
+     * 详细地址
+     */
+    private String address;
+
+    /**
      * 条款内容
      */
     private String remark;

+ 6 - 1
hx-sale/src/main/java/com/fjhx/sale/flow/ContractFlow.java

@@ -9,7 +9,9 @@ import com.baomidou.mybatisplus.core.toolkit.IdWorker;
 import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
 import com.fjhx.area.utils.CustomizeAreaUtil;
 import com.fjhx.common.constant.SourceConstant;
+import com.fjhx.common.enums.CodingRuleEnum;
 import com.fjhx.common.enums.FlowStatusEnum;
+import com.fjhx.common.service.coding.CodingRuleService;
 import com.fjhx.file.utils.ObsFileUtil;
 import com.fjhx.flow.core.FlowDelegate;
 import com.fjhx.sale.entity.contract.dto.ContractDto;
@@ -25,6 +27,7 @@ import com.fjhx.sale.service.contract.ContractShipmentService;
 import com.fjhx.sale.util.code.CodeEnum;
 import com.obs.services.internal.ServiceException;
 import com.ruoyi.common.utils.SecurityUtils;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 import java.util.Date;
@@ -39,6 +42,8 @@ import java.util.List;
 @Component
 public class ContractFlow extends FlowDelegate {
 
+    @Autowired
+    private CodingRuleService codingRuleService;
 
     @Override
     public String getFlowKey() {
@@ -63,7 +68,7 @@ public class ContractFlow extends FlowDelegate {
         ContractDto contract = submitData.toJavaObject(ContractDto.class);
         //赋值城市省份信息
         CustomizeAreaUtil.setAreaId(contract);
-        contract.setCode(CodeEnum.CONTRACT.getCode());
+        contract.setCode(codingRuleService.createCode(CodingRuleEnum.CONTRACT.getKey(),contract.getBuyCorporationId()));
         contract.setUserName(SecurityUtils.getUsername());
         contract.setStatus(FlowStatusEnum.UNDER_REVIEW.getKey());
         contract.setBuyCityId(contract.getCityId());

+ 3 - 4
hx-sale/src/main/java/com/fjhx/sale/flow/EhsdPurchaseFlow.java

@@ -25,7 +25,6 @@ import com.obs.services.internal.ServiceException;
 import com.ruoyi.common.utils.SecurityUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
-import org.springframework.transaction.annotation.Transactional;
 
 import java.math.BigDecimal;
 import java.util.ArrayList;
@@ -81,9 +80,9 @@ public class EhsdPurchaseFlow extends FlowDelegate {
         EhsdPurchaseDto purchase = submitData.toJavaObject(EhsdPurchaseDto.class);
         //赋值城市省份信息
         CustomizeAreaUtil.setAreaId(purchase);
-        purchase.setBuyCityId(purchase.getCityId());
-        purchase.setBuyCountryId(purchase.getCountryId());
-        purchase.setBuyProvinceId(purchase.getProvinceId());
+        purchase.setSellCityId(purchase.getCityId());
+        purchase.setSellCountryId(purchase.getCountryId());
+        purchase.setSellProvinceId(purchase.getProvinceId());
 
         purchase.setCode(CodeEnum.PURCHASE.getCode());
         purchase.setStatus(PurchaseStatusEnum.UNDER_REVIEW.getKey());

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

@@ -32,5 +32,5 @@ public interface EhsdPurchaseProductMapper extends BaseMapper<EhsdPurchaseProduc
      * @param contractIds
      * @return
      */
-    Map<Long, BigDecimal> getGroupSumAmount(List<Long> contractIds);
+    Map<Long, String> getGroupSumAmount(List<Long> contractIds);
 }

+ 3 - 3
hx-sale/src/main/java/com/fjhx/sale/service/contract/impl/ContractProductServiceImpl.java

@@ -135,8 +135,8 @@ public class ContractProductServiceImpl extends ServiceImpl<ContractProductMappe
         if(StringUtils.isNotEmpty(dto.getKeyword())){
             wrapper.keyword(dto.getKeyword(),new SqlField("t1.`contractCode`"),new SqlField("t1.`userName`"));
         }
-        if(StringUtils.isNotEmpty(dto.getKeyword())){
-            wrapper.in("t1.id",Arrays.asList(dto.getIds()));
+        if(StringUtils.isNotEmpty(dto.getIds())){
+            wrapper.in("t1.id",Arrays.asList(dto.getIds().split(",")));
         }
         Page<ContractProductVo> page = this.baseMapper.getEHSDPage(dto.getPage(), wrapper);
         List<ContractProductVo> list = page.getRecords();
@@ -146,7 +146,7 @@ public class ContractProductServiceImpl extends ServiceImpl<ContractProductMappe
                 item.setProductCode(product.getCode());
                 item.setProductUnit(product.getUnit());
                 item.setProductType(product.getType());
-                item.setProductName(product.getName());
+//                item.setProductName(product.getName());
                 item.setProductSpec(product.getSpec());
                 item.setProductCategoryId(product.getProductClassifyId());
             });

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

@@ -188,46 +188,62 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
         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);
+            Map<Long,String> ehsdAmountMap = ehsdPurchaseProductService.getGroupSumAmount(contractIds);
             List<PurchaseDetailVo> otherAmountList = purchaseDetailService.getSumCountInDataResourceIds(contractIds);
-            Map<Long,BigDecimal> otherAmountMap = otherAmountList.stream().collect(Collectors.toMap(PurchaseDetailVo::getDataResourceId,PurchaseDetailVo::getSumCount));
+            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);//先设置退税金额
+                v.setRefundableAmount(BigDecimal.ZERO);//暂时先设置退税金额为0
                 if(MapUtils.isNotEmpty(ehsdAmountMap)){    //计算EHSD租户应付货款
-                    v.setEhsdSumAmount(ehsdAmountMap.getOrDefault(v.getContractId(),null));
+                    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)){  //计算其他租户应付货款
-                    v.setOtherumAmount(otherAmountMap.getOrDefault(v.getContractId(),null));
+                    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.setOtherumAmount(amount.multiply(rate));
+                    }else{
+                        v.setOtherumAmount(BigDecimal.ZERO);
+                    }
                 }
                 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()));
+                    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
+                            (v.getAgencyFee()==null?BigDecimal.ZERO:v.getAgencyFee().multiply(new BigDecimal(map.getOrDefault(v.getAgencyFeeCurrency(),BigDecimal.ONE).toString()))).add
+                            (v.getPortMixedFee()==null?BigDecimal.ZERO:v.getPortMixedFee().multiply(new BigDecimal(map.getOrDefault(v.getPortMixedFeeCurrency(),BigDecimal.ONE).toString()))).add
+                            (v.getInspectionRedPack()==null?BigDecimal.ZERO:v.getInspectionRedPack().multiply(new BigDecimal(map.getOrDefault(v.getInspectionRedPackCurrency(),BigDecimal.ONE).toString()))).add
+                            (v.getCommission()==null?BigDecimal.ZERO:v.getCommission().multiply(new BigDecimal(map.getOrDefault(v.getCommissionCurrency(),BigDecimal.ONE).toString()))).add
+                            (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.getOtherumAmount()==null?BigDecimal.ZERO: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.setExpenditureAmount(v.getTrailerFee()==null?BigDecimal.ZERO:v.getTrailerFee().multiply(new BigDecimal(currencyRateMap.getOrDefault(v.getTrailerFeeCurrency(),BigDecimal.ONE).toString())).add
+                            (v.getCustomsFee()==null?BigDecimal.ZERO:v.getCustomsFee().multiply(new BigDecimal(currencyRateMap.getOrDefault(v.getCustomsFeeCurrency(),BigDecimal.ONE).toString()))).add
+                            (v.getAgencyFee()==null?BigDecimal.ZERO:v.getAgencyFee().multiply(new BigDecimal(currencyRateMap.getOrDefault(v.getAgencyFeeCurrency(),BigDecimal.ONE).toString()))).add
+                            (v.getPortMixedFee()==null?BigDecimal.ZERO:v.getPortMixedFee().multiply(new BigDecimal(currencyRateMap.getOrDefault(v.getPortMixedFeeCurrency(),BigDecimal.ONE).toString()))).add
+                            (v.getInspectionRedPack()==null?BigDecimal.ZERO:v.getInspectionRedPack().multiply(new BigDecimal(currencyRateMap.getOrDefault(v.getInspectionRedPackCurrency(),BigDecimal.ONE).toString()))).add
+                            (v.getCommission()==null?BigDecimal.ZERO:v.getCommission().multiply(new BigDecimal(currencyRateMap.getOrDefault(v.getCommissionCurrency(),BigDecimal.ONE).toString()))).add
+                            (v.getOther()==null?BigDecimal.ZERO:v.getOther().multiply(new BigDecimal(currencyRateMap.getOrDefault(v.getOtherCurrency(),BigDecimal.ONE).toString()))).add
+                            (v.getEhsdSumAmount()==null?BigDecimal.ZERO:v.getEhsdSumAmount()).add
+                            (v.getOtherumAmount()==null?BigDecimal.ZERO:v.getOtherumAmount()));
                 }
                 //计算毛利 收入-支出
                 v.setGross(v.getExpenditureAmount().subtract(v.getIncomeAmount()));

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

@@ -52,5 +52,5 @@ public interface EhsdPurchaseProductService extends BaseService<EhsdPurchaseProd
      * @param contractIds
      * @return
      */
-    Map<Long, BigDecimal> getGroupSumAmount(List<Long> contractIds);
+    Map<Long, String> getGroupSumAmount(List<Long> contractIds);
 }

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

@@ -64,7 +64,7 @@ public class EhsdPurchaseProductServiceImpl extends ServiceImpl<EhsdPurchaseProd
      * @return
      */
     @Override
-    public Map<Long, BigDecimal> getGroupSumAmount(List<Long> contractIds) {
+    public Map<Long, String> getGroupSumAmount(List<Long> contractIds) {
         return baseMapper.getGroupSumAmount(contractIds);
     }
 

+ 2 - 0
hx-sale/src/main/resources/mapper/contract/ContractProductMapper.xml

@@ -25,6 +25,7 @@
                     t1.create_time AS ct,
                     "外销合同" AS orderType,
                     t1.id,
+                    t1.product_model AS productModel,
                     t1.contract_id,
                     t1.product_id,
                     t2.`code` AS `contractCode`,
@@ -43,6 +44,7 @@
                     t1.create_time AS ct,
                     "样品单" AS orderType,
                     t1.id,
+                    t1.product_model AS productModel,
                     t1.sample_id,
                     t1.product_id,
                     t2.`code` AS `contractCode`,

+ 6 - 5
hx-sale/src/main/resources/mapper/purchase/EhsdPurchaseProductMapper.xml

@@ -23,18 +23,19 @@
 
     <select id="getGroupSumAmount" resultType="java.util.Map">
         SELECT
-            SUM(amount) ,
-            data_resource_id
+            CONCAT( IFNULL( SUM( t1.amount ), 0 ), "-", IFNULL(t2.currency,"¥") ),
+            t1.data_resource_id
         FROM
-            ehsd_purchase_product
+            ehsd_purchase_product t1
+        LEFT JOIN ehsd_purchase t2 ON t1.purchase_id = t2.id
         WHERE
         t2.`status` &gt;= 30
         AND t2.`status` &lt; 88
         <if test="contractIds neq null and contractIds.size() > 0">
-            <foreach collection="contractIds" item="contractId" open="AND data_resource_id IN (" separator="," close=")">
+            <foreach collection="contractIds" item="contractId" open="AND t1.data_resource_id IN (" separator="," close=")">
                 #{contractId}
             </foreach>
         </if>
-        GROUP BY data_resource_id
+        GROUP BY t1.data_resource_id
     </select>
 </mapper>