ezhizao_zx 1 ano atrás
pai
commit
f47a45efbe

+ 1 - 1
src/main/java/cn/ezhizao/project/business/collection/domain/CollectionExcelLoopModel.java

@@ -43,7 +43,7 @@ public class CollectionExcelLoopModel {
     private Date arriveTime;
 
     // 代理记账
-    @Excel(name = "收款金额")
+    @Excel(name = "收款金额")
     private BigDecimal amount;
     // 代理记账单价
     @Excel(name = "合同总金额")

+ 1 - 1
src/main/java/cn/ezhizao/project/business/collection/domain/CollectionExcelOnceModel.java

@@ -43,7 +43,7 @@ public class CollectionExcelOnceModel {
     private Date arriveTime;
 
     // 代理记账
-    @Excel(name = "收款金额")
+    @Excel(name = "收款金额")
     private BigDecimal amount;
     // 代理记账单价
     @Excel(name = "合同总金额")

+ 49 - 8
src/main/java/cn/ezhizao/project/business/collection/service/impl/BizCollectionServiceImpl.java

@@ -33,6 +33,8 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import static cn.ezhizao.common.utils.SecurityUtils.getUserId;
+
 /**
  * @author 朱汕
  */
@@ -94,10 +96,15 @@ public class BizCollectionServiceImpl extends ServiceImpl<BizCollectionMapper, B
         StringBuilder failureMsg = new StringBuilder();
         for (CollectionExcelLoopModel item: collects) {
             // 获取合同信息
-            BizArchiveInput archiveInput = archiveInputService.query().eq("contract_no", item.getContractNo()).eq("tenant_id", tenantId).list().stream().findFirst().orElse(null);
+            BizArchiveInput archiveInput = archiveInputService.query().eq("contract_no", item.getContractNo()).eq("service_type",1).eq("tenant_id", tenantId).list().stream().findFirst().orElse(null);
             if (archiveInput == null) {
                 failureNum++;
-                failureMsg.append("<br/>").append(failureNum).append("、合同 ").append(item.getContractNo()).append(" 不存在");
+                failureMsg.append("<br/>").append(failureNum).append("、合同 ").append(item.getContractNo()).append(" 不存在或不是循环合同");
+                continue;
+            }
+            if(archiveInput.getTrueAmount().subtract(item.getContractAmount()).compareTo(BigDecimal.ZERO) != 0){
+                failureNum++;
+                failureMsg.append("<br/>").append(failureNum).append("、合同 ").append(item.getContractNo()).append("合同总金额不一致");
                 continue;
             }
             BizCompany company = companies.stream().filter(v -> v.getName().equals(item.getCompanyName())).findFirst().orElse(null);
@@ -134,11 +141,23 @@ public class BizCollectionServiceImpl extends ServiceImpl<BizCollectionMapper, B
                 failureMsg.append("<br/>").append(failureNum).append("、订单 ").append(item.getContractNo()).append("的没有返税申报任务");
                 continue;
             }
+            //查询收款记录
+            List<BizCollection> collected = this.query().eq("contract_id", archiveInput.getId()).eq("status", 1).list();
+            BigDecimal collectedAmount = BigDecimal.valueOf(collected.stream().mapToDouble(v -> v.getArriveAmount().doubleValue()).sum());
+
+            if(item.getAmount().subtract(archiveInput.getTrueAmount().subtract(collectedAmount)).compareTo(BigDecimal.ZERO) >0){
+                failureNum++;
+                failureMsg.append("<br/>").append(failureNum).append("、订单 ").append(item.getContractNo()).append("收款金额不能大于未收款金额");
+                continue;
+            }
+
             BizCollection bizCollection = new BizCollection();
             bizCollection.setId(snowflakeIdWorker.nextId());
             bizCollection.setContractId(archiveInput.getId());
             bizCollection.setFlowNo(String.valueOf(snowflakeIdWorker.nextId()));
-//            bizCollection.setFormDate(DateTime.of(item.getFormDate()).toTimestamp());
+            bizCollection.setApplierId(getUserId());
+            //实际付款时间默认未当前时间
+            bizCollection.setActuallyDate(DateTime.now().toTimestamp());
             bizCollection.setContractNo(archiveInput.getContractNo());
             bizCollection.setCompanyId(archiveInput.getCompanyId());
 //            bizCollection.setSubsidiaryBankAccount(item.getSubsidiaryBankAccount());
@@ -174,9 +193,9 @@ public class BizCollectionServiceImpl extends ServiceImpl<BizCollectionMapper, B
                 detail.setCompanyId(company.getId());
                 detail.setTaskTypeId(l.getTaskTypeId());
                 if (i == contractDetails.size() - 1) {
-                    detail.setArriveAmount(item.getContractAmount().subtract(remain));
+                    detail.setArriveAmount(item.getAmount().subtract(remain));
                 } else {
-                    detail.setArriveAmount(item.getContractAmount().divide(detailSum, 4, RoundingMode.HALF_UP).multiply(l.getAmount()).setScale(2, RoundingMode.HALF_UP));
+                    detail.setArriveAmount(item.getAmount().divide(detailSum, 4, RoundingMode.HALF_UP).multiply(l.getAmount()).setScale(2, RoundingMode.HALF_UP));
                     remain = remain.add(detail.getArriveAmount());
 //                    remain = item.getC
                 }
@@ -241,10 +260,16 @@ public class BizCollectionServiceImpl extends ServiceImpl<BizCollectionMapper, B
         StringBuilder failureMsg = new StringBuilder();
         for (CollectionExcelOnceModel item: collects) {
             // 获取合同信息
-            BizArchiveInput archiveInput = archiveInputService.query().eq("contract_no", item.getContractNo()).eq("tenant_id", tenantId).list().stream().findFirst().orElse(null);
+            BizArchiveInput archiveInput = archiveInputService.query().eq("contract_no", item.getContractNo()).eq("service_type",2).eq("tenant_id", tenantId).list().stream().findFirst().orElse(null);
+
             if (archiveInput == null) {
                 failureNum++;
-                failureMsg.append("<br/>").append(failureNum).append("、合同 ").append(item.getContractNo()).append(" 不存在");
+                failureMsg.append("<br/>").append(failureNum).append("、合同 ").append(item.getContractNo()).append(" 不存在或不是单次合同");
+                continue;
+            }
+            if(archiveInput.getTrueAmount().subtract(item.getContractAmount()).compareTo(BigDecimal.ZERO) != 0){
+                failureNum++;
+                failureMsg.append("<br/>").append(failureNum).append("、合同 ").append(item.getContractNo()).append("合同总金额不一致");
                 continue;
             }
             BizCompany company = companies.stream().filter(v -> v.getName().equals(item.getCompanyName())).findFirst().orElse(null);
@@ -258,6 +283,7 @@ public class BizCollectionServiceImpl extends ServiceImpl<BizCollectionMapper, B
                 failureMsg.append("<br/>").append(failureNum).append("、订单 ").append(item.getContractNo()).append("的客户不是").append(item.getCompanyName());
                 continue;
             }
+
             List<BizArchiveInputDetail> contractDetails = archiveInputDetailService.query().eq("contract_id", archiveInput.getId()).list();
             // 判断明细信息是否和导入信息相符
             // 不相符添加 failureNum 并转到下一条。
@@ -286,9 +312,24 @@ public class BizCollectionServiceImpl extends ServiceImpl<BizCollectionMapper, B
 //                failureMsg.append("<br/>").append(failureNum).append("、订单 ").append(item.getContractNo()).append("的没有其他任务");
 //                continue;
 //            }
+
+            List<BizCollection> collected = this.query().eq("contract_id", archiveInput.getId()).eq("status", 1).list();
+            BigDecimal collectedAmount = BigDecimal.valueOf(collected.stream().mapToDouble(v -> v.getArriveAmount().doubleValue()).sum());
+
+            if(item.getAmount().subtract(archiveInput.getTrueAmount().subtract(collectedAmount)).compareTo(BigDecimal.ZERO) >0){
+                failureNum++;
+                failureMsg.append("<br/>").append(failureNum).append("、订单 ").append(item.getContractNo()).append("收款金额不能大于未收款金额");
+                continue;
+            }
+
+
+
             BizCollection bizCollection = new BizCollection();
             bizCollection.setId(snowflakeIdWorker.nextId());
             bizCollection.setContractId(archiveInput.getId());
+            bizCollection.setApplierId(getUserId());
+            //实际付款时间默认未当前时间
+            bizCollection.setActuallyDate(DateTime.now().toTimestamp());
             bizCollection.setFlowNo(String.valueOf(snowflakeIdWorker.nextId()));
             bizCollection.setContractNo(archiveInput.getContractNo());
             bizCollection.setCompanyId(archiveInput.getCompanyId());
@@ -330,7 +371,7 @@ public class BizCollectionServiceImpl extends ServiceImpl<BizCollectionMapper, B
 //                if (l.getTaskTypeId().equals(9L)) {
 //                    detail.setArriveAmount(item.getOtherAmount());
 //                }
-                detail.setArriveAmount(l.getAmount());
+                detail.setArriveAmount(item.getAmount());
                 detail.setContractDetailId(l.getId());
                 detail.setContractId(l.getContractId());
                 detail.setTenantId(tenantId);

+ 2 - 1
src/main/java/cn/ezhizao/project/business/order/domain/BizArchiveInputDetail.java

@@ -39,7 +39,7 @@ public class BizArchiveInputDetail extends BaseEntity
 
     /** 实收金额 */
     @Excel(name = "实收金额")
-    @ApiModelProperty(value = "实收金额")
+    @TableField(exist = false)
     private BigDecimal trueAmount;
 
     /** 月数 */
@@ -117,6 +117,7 @@ public class BizArchiveInputDetail extends BaseEntity
     private Long fromId;
 
     @ApiModelProperty("已付款")
+    @TableField(exist = false)
     private BigDecimal arrived;
 
 }