瀏覽代碼

Merge branch 'pool_677'

# Conflicts:
#	models/fms/contract_invoice.go
ziwen 1 年之前
父節點
當前提交
8ba6951ca2

+ 1 - 1
controller/contract/pre_register.go

@@ -863,7 +863,7 @@ func (rg *PreRegisterController) Detail(c *gin.Context) {
 	}
 
 	if req.DetailType == 1 {
-		dupList, e := fms.GetDuplicateContractInvoiceDetailItemListWithType(nItme.CompanyName, nItme.StartDate, nItme.EndDate)
+		dupList, e := fms.GetDuplicateContractInvoiceDetailItemListWithType(nItme.CompanyName, nItme.StartDate, nItme.EndDate, req.ContractType, req.HasPayment)
 		if e != nil {
 			err = fmt.Errorf("获取开票到款列表失败, Err: %s", e.Error())
 			return

+ 21 - 15
controller/contract/register.go

@@ -423,7 +423,7 @@ func (rg *RegisterController) Add(c *gin.Context) {
 		//	sellerMap[sellerList[i].SellerId] = sellerList[i]
 		//}
 		//处理重复公司名日期等重复的开票到款记录
-		dupList, e := fms.GetDuplicateContractInvoiceDetailItemList(ob.CompanyName, req.StartDate, req.EndDate)
+		dupList, e := fms.GetDuplicateContractInvoiceDetailItemList(ob.CompanyName, req.StartDate, req.EndDate, req.ContractType, req.HasPayment)
 		if e != nil {
 			err = fmt.Errorf("获取开票到款列表失败, Err: %s", e.Error())
 			return
@@ -693,7 +693,7 @@ func (rg *RegisterController) Add(c *gin.Context) {
 			return
 		}
 		//处理重复公司名日期等重复的开票到款记录
-		dupList, e := fms.GetDuplicateContractInvoiceDetailItemList(ob.CompanyName, req.StartDate, req.EndDate)
+		dupList, e := fms.GetDuplicateContractInvoiceDetailItemList(ob.CompanyName, req.StartDate, req.EndDate, req.ContractType, req.HasPayment)
 		if e != nil {
 			err = fmt.Errorf("获取开票到款列表失败, Err: %s", e.Error())
 			return
@@ -2979,13 +2979,15 @@ func (rg *RegisterController) Import(c *gin.Context) {
 							resp.Fail(fmt.Sprintf("第FICC销售名称和权益销售名称不可都为空, 请按模板导入", i+1), c)
 							return
 						}
-						sellerItem := sellerMap[v]
-						if sellerItem == nil {
-							resp.Fail(fmt.Sprintf("第%d行权益销售名称与系统销售不匹配, 请核对名称后导入", i+1), c)
-							return
+						if v != ""{
+							sellerItem := sellerMap[v]
+							if sellerItem == nil {
+								resp.Fail(fmt.Sprintf("第%d行权益销售名称与系统销售不匹配, 请核对名称后导入", i+1), c)
+								return
+							}
+							rowRegister.RaiSellerId = sellerItem.SellerId
+							rowRegister.RaiSellerName = sellerItem.SellerName
 						}
-						rowRegister.RaiSellerId = sellerItem.SellerId
-						rowRegister.RaiSellerName = sellerItem.SellerName
 						continue
 					}
 					// FICC大套餐
@@ -3577,7 +3579,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
 
 				//处理重复公司名日期等重复的开票到款记录
 				sellerItemMap := make(map[int]*crm.SellerAdminWithGroupTeam)
-				dupList, e := fms.GetDuplicateContractInvoiceDetailItemList(rowRegister.CompanyName, rowRegister.StartDate.Format(utils.FormatDate), rowRegister.EndDate.Format(utils.FormatDate))
+				dupList, e := fms.GetDuplicateContractInvoiceDetailItemList(rowRegister.CompanyName, rowRegister.StartDate.Format(utils.FormatDate), rowRegister.EndDate.Format(utils.FormatDate), rowRegister.ContractType, rowRegister.HasPayment)
 				if e != nil {
 					err = fmt.Errorf("获取开票到款列表失败, Err: %s", e.Error())
 					return
@@ -3862,7 +3864,7 @@ func (rg *RegisterController) CheckContractDuplicate(c *gin.Context) {
 	existPars := make([]interface{}, 0)
 	if req.CompanyName != "" {
 		// 是否存在相同的合同名称的登记
-		existCond = ` company_name = ?`
+		existCond = ` a.company_name = ?`
 		existPars = append(existPars, req.CompanyName)
 	}
 
@@ -3879,9 +3881,9 @@ func (rg *RegisterController) CheckContractDuplicate(c *gin.Context) {
 			return
 		}
 		if existCond != "" {
-			existCond += ` AND (start_date =? and end_date=?)`
+			existCond += ` AND (a.start_date =? and a.end_date=?)`
 		} else {
-			existCond = ` start_date = ? and end_date=?`
+			existCond = ` a.start_date = ? and a.end_date=?`
 		}
 
 		existPars = append(existPars, startDate, endDate)
@@ -3891,6 +3893,10 @@ func (rg *RegisterController) CheckContractDuplicate(c *gin.Context) {
 		resp.Fail("请输入合同名称或者合同有效期", c)
 		return
 	}
+
+	existCond += ` AND a.is_deleted = 0 AND a.contract_type = ? AND a.has_payment = ?`
+	existPars = append(existPars, req.ContractType, req.HasPayment)
+
 	data := fms.CheckContractDuplicateResp{
 		Exist: 0,
 	}
@@ -3940,10 +3946,10 @@ func (rg *RegisterController) CheckContractDuplicate(c *gin.Context) {
 		templateIdStr := strings.Join(ids, ",")
 
 		for _, v := range dupList {
-			if serviceIds, ok := serviceIdMap[v.ContractRegisterId]; ok{
-				if serviceIds == templateIdStr{
+			if serviceIds, ok := serviceIdMap[v.ContractRegisterId]; ok {
+				if serviceIds == templateIdStr {
 					data.Exist = 1
-					if _, ok2 := typeIdMap[v.ContractRegisterId]; ok2{
+					if _, ok2 := typeIdMap[v.ContractRegisterId]; ok2 {
 						data.Type = 1
 					}
 				}

+ 24 - 6
models/fms/contract_invoice.go

@@ -614,13 +614,15 @@ func (c *ContractInvoice) FetchByRegisterId(registerId int) (items []*ContractIn
 }
 
 // GetDuplicateContractInvoiceDetailItemListWithType 预登记列表详情用-获取开票到款列表
-func GetDuplicateContractInvoiceDetailItemListWithType(companyName, startDate, endDate string) (itemList []*ContractInvoiceDetailItem, err error) {
+func GetDuplicateContractInvoiceDetailItemListWithType(companyName, startDate, endDate string,contractType, hasPayment int) (itemList []*ContractInvoiceDetailItem, err error) {
 	list := make([]*InvoiceDetailItem, 0)
 	err = global.DEFAULT_MYSQL.Table("contract_invoice as a ").
 		Select(" a.*,IF(p.seller_id > 0, 1, 0) AS has_invoice_seller  ").
 		Joins(" JOIN contract_register as b ON a.contract_register_id = b.contract_register_id ").
 		Joins("JOIN contract_pre_register AS p ON p.invoice_id = a.contract_invoice_id OR p.arrive_id = a.contract_invoice_id ").
-		Where(fmt.Sprintf("a.is_deleted = 0 AND b.company_name = '%s' AND b.start_date= '%s' AND b.end_date= '%s' AND b.is_deleted=0 AND (a.invoice_type=3 OR a.invoice_type=4) ", companyName, startDate, endDate)).
+		Where(fmt.Sprintf("a.is_deleted = 0 AND b.company_name = '%s' AND b.start_date= '%s' AND b.end_date= '%s'" +
+			" AND b.is_deleted=0 AND (a.invoice_type=3 OR a.invoice_type=4) " +
+			"AND b.contract_type=? AND b.has_payment=?", companyName, startDate, endDate), contractType, hasPayment).
 		Order("a.contract_invoice_id ASC").
 		Find(&list).Error
 	if err != nil {
@@ -641,12 +643,12 @@ type DupInvoice struct {
 }
 
 // GetDuplicateContractInvoiceDetailItemList 预登记列表详情用-获取开票到款列表
-func GetDuplicateContractInvoiceDetailItemList(companyName, startDate, endDate string) (list []*DupInvoice, err error) {
+func GetDuplicateContractInvoiceDetailItemList(companyName, startDate, endDate string, contractType, hasPayment int) (list []*DupInvoice, err error) {
 	err = global.DEFAULT_MYSQL.Table("contract_invoice as a ").
-		Select(" a.*,GROUP_CONCAT(c.service_template_id ORDER BY c.service_template_id ) AS template_ids ").
+		Select(" a.*,GROUP_CONCAT(DISTINCT c.service_template_id ORDER BY c.service_template_id ) AS template_ids ").
 		Joins(" JOIN contract_register as b ON a.contract_register_id = b.contract_register_id ").
 		Joins("JOIN contract_service AS c ON a.contract_register_id = c.contract_register_id").
-		Where(fmt.Sprintf("a.is_deleted = 0 AND b.company_name = '%s' AND b.start_date= '%s' AND b.end_date= '%s' AND b.is_deleted=0 AND (a.invoice_type=3 OR a.invoice_type=4) ", companyName, startDate, endDate)).
+		Where(fmt.Sprintf("a.is_deleted = 0 AND b.company_name = '%s' AND b.start_date= '%s' AND b.end_date= '%s' AND b.is_deleted=0 AND (a.invoice_type=3 OR a.invoice_type=4) AND b.contract_type=? AND b.has_payment=?", companyName, startDate, endDate), contractType, hasPayment).
 		Group("a.contract_register_id").
 		Order("a.contract_invoice_id ASC").
 		Find(&list).Error
@@ -788,4 +790,20 @@ func GetInvoiceListByFix() (results []*ContractInvoice, err error) {
 	sql := `SELECT * FROM contract_invoice WHERE invoice_type = 2 AND seller_id = 0 `
 	err = global.DEFAULT_MYSQL.Raw(sql).Find(&results).Error
 	return
-}
+}
+
+// GetDuplicateContractInvoiceDetailItemList 补录合同用-获取开票到款列表
+func GetDuplicateContractInvoiceDetailItemListForSupplement(companyName, startDate, endDate string, contractType, hasPayment int) (list []*DupInvoice, err error) {
+	err = global.DEFAULT_MYSQL.Table("contract_invoice as a ").
+		Select(" a.*,GROUP_CONCAT(DISTINCT c.service_template_id ORDER BY c.service_template_id ) AS template_ids ").
+		Joins(" JOIN contract_register as b ON a.contract_register_id = b.contract_register_id ").
+		Joins("JOIN contract_service AS c ON a.contract_register_id = c.contract_register_id").
+		Where(fmt.Sprintf("a.is_deleted = 0 AND b.company_name = '%s' AND b.start_date= '%s' AND b.end_date= '%s' AND b.is_deleted=0 AND b.contract_type=? AND b.has_payment=?", companyName, startDate, endDate), contractType, hasPayment).
+		Group("a.contract_register_id").
+		Order("a.contract_invoice_id ASC").
+		Find(&list).Error
+	if err != nil {
+		return
+	}
+	return
+}

+ 2 - 0
models/fms/contract_pre_register.go

@@ -227,6 +227,8 @@ type PreRegisterDetailReq struct {
 	InvoiceId          int `gorm:"column:invoice_id" json:"invoice_id" description:"开票ID"`
 	ArriveId           int `gorm:"column:arrive_id" json:"arrive_id" description:"到款ID"`
 	DetailType         int `json:"detail_type" description:"请求类型"`
+	ContractType       int `json:"contract_type" binding:"oneof=1 2 3 4" description:"合同类型: 1-新签; 2-续约; 3-代付; 4-补充协议"`
+	HasPayment         int `json:"has_payment" description:"是否有代付: 0-无; 1-有"`
 }
 
 // ContractPreRegisterDetail 预登记详情

+ 6 - 4
models/fms/contract_register.go

@@ -908,10 +908,12 @@ func UpdateSupplementContractPreRegister(item *ContractRegister, serviceAmountLi
 }
 
 type CheckContractDuplicateReq struct {
-	CompanyName string                  `json:"company_name" form:"company_name" description:"客户名称"`
-	StartDate   string                  `json:"start_date" form:"start_date" description:"合同开始日期"`
-	EndDate     string                  `json:"end_date" form:"end_date" description:"合同结束日期"`
-	Services    []ContractServiceAddReq `json:"services" description:"服务套餐内容"`
+	CompanyName  string                  `json:"company_name" form:"company_name" description:"客户名称"`
+	StartDate    string                  `json:"start_date" form:"start_date" description:"合同开始日期"`
+	EndDate      string                  `json:"end_date" form:"end_date" description:"合同结束日期"`
+	ContractType int                     `json:"contract_type" binding:"oneof=1 2 3 4" description:"合同类型: 1-新签; 2-续约; 3-代付; 4-补充协议"`
+	HasPayment   int                     `json:"has_payment" description:"是否有代付: 0-无; 1-有"`
+	Services     []ContractServiceAddReq `json:"services" description:"服务套餐内容"`
 }
 
 func CheckContractDuplicate(condition string, pars []interface{}) (list []*ContractRegister, err error) {