ziwen 1 year ago
parent
commit
f701344640

+ 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

+ 4 - 2
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 {

+ 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 预登记详情

+ 14 - 15
models/fms/contract_register.go

@@ -616,8 +616,8 @@ func UpdateContractPreRegister(item *ContractRegister, updateCols []string, serv
 	}
 
 	for i := range invoiceList {
-		fmt.Println("invoiceList[i].SellerName",invoiceList[i].SellerName)
-		fmt.Println("invoiceList[i].SellerId",invoiceList[i].SellerId)
+		fmt.Println("invoiceList[i].SellerName", invoiceList[i].SellerName)
+		fmt.Println("invoiceList[i].SellerId", invoiceList[i].SellerId)
 		if invoiceList[i].ContractInvoiceId == 0 {
 			if e := invoiceList[i].Create(); e != nil {
 				err = e
@@ -663,9 +663,9 @@ func UpdateContractPreRegister(item *ContractRegister, updateCols []string, serv
 		SellerTeamId:       sellerItem.TeamId,
 		SellerTeamName:     sellerItem.TeamName,
 	}
-	if registerType == 3{
-		tx.Model(&invoiceItem).Select([]string{"StartDate", "EndDate", "CurrencyUnit","SellerId",
-			"SellerName","SellerGroupId","SellerGroupName","SellerTeamId","SellerTeamName"}).Where("contract_register_id = ? AND invoice_type = 4", item.ContractRegisterId).Updates(invoiceItem)
+	if registerType == 3 {
+		tx.Model(&invoiceItem).Select([]string{"StartDate", "EndDate", "CurrencyUnit", "SellerId",
+			"SellerName", "SellerGroupId", "SellerGroupName", "SellerTeamId", "SellerTeamName"}).Where("contract_register_id = ? AND invoice_type = 4", item.ContractRegisterId).Updates(invoiceItem)
 	} else {
 		tx.Model(&invoiceItem).Select([]string{"StartDate", "EndDate", "CurrencyUnit"}).Where("contract_register_id", item.ContractRegisterId).Updates(invoiceItem)
 	}
@@ -789,14 +789,12 @@ func UpdateContractRegisterPre(item *ContractRegister, updateCols []string, serv
 			otherInvoiceItem.SellerTeamId = invoiceList[0].SellerTeamId
 			otherInvoiceItem.SellerTeamName = invoiceList[0].SellerTeamName
 		}
-		tx.Model(&otherInvoiceItem).Select([]string{"ServiceProductId","SellerId", "SellerName", "SellerGroupId","SellerGroupName","SellerTeamId","SellerTeamName"}).Updates(otherInvoiceItem)
+		tx.Model(&otherInvoiceItem).Select([]string{"ServiceProductId", "SellerId", "SellerName", "SellerGroupId", "SellerGroupName", "SellerTeamId", "SellerTeamName"}).Updates(otherInvoiceItem)
 	} else {
 		otherInvoiceItem.ContractInvoiceId = ppItem.InvoiceId
 		tx.Model(&otherInvoiceItem).Select([]string{"ServiceProductId"}).Updates(otherInvoiceItem)
 	}
 
-
-
 	//更新另一类型的invoice表数据
 	invoiceItem := ContractInvoice{
 		ContractRegisterId: item.ContractRegisterId,
@@ -910,13 +908,15 @@ 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) {
+func CheckContractDuplicate(condition string, pars []interface{}) (list []*ContractRegister, err error) {
 	query := global.DEFAULT_MYSQL.Table("contract_register AS a").
 		Select("a.* ").
 		Joins(" JOIN contract_service AS b ON a.contract_register_id = b.contract_register_id ").
@@ -926,7 +926,6 @@ func CheckContractDuplicate(condition string, pars []interface{}) (list []*Contr
 	return
 }
 
-
 type CheckContractDuplicateResp struct {
 	Exist int `json:"exist" description:"是否存在重复的合同:0不存在,1存在"`
 }
@@ -937,4 +936,4 @@ func CheckContractServiceDuplicate(registerIds []int) (ids []*string, err error)
 		Where("contract_register_id IN (?)", registerIds).
 		Group("contract_register_id").Scan(&ids).Error
 	return
-}
+}