Bläddra i källkod

Merge branch 'fms_2.5'

ziwen 2 år sedan
förälder
incheckning
5bb624473f

+ 4 - 1
controller/census/invoice_payment.go

@@ -578,7 +578,7 @@ func (ct *InvoicePaymentController) List(c *gin.Context) {
 			cond += ` AND (c.invoice_time BETWEEN ? AND ?) AND (d.invoice_time BETWEEN ? AND ?) `
 			pars = append(pars, st, ed, st, ed)
 		}
-	}else if req.StartDate != "" && req.EndDate != "" {
+	} else if req.StartDate != "" && req.EndDate != "" {
 		st := fmt.Sprint(req.StartDate, " 00:00:00")
 		ed := fmt.Sprint(req.EndDate, " 23:59:59")
 		cond += ` AND ((c.invoice_time BETWEEN ? AND ?) or (d.invoice_time BETWEEN ? AND ?))`
@@ -662,6 +662,7 @@ func (ct *InvoicePaymentController) List(c *gin.Context) {
 		queryRegisterIds = append(queryRegisterIds, registerList[i].ContractRegisterId)
 	}
 
+	//fmt.Println("queryRegisterIds:",queryRegisterIds)
 	results := new(fms.InvoicePaymentCensusResp)
 	if len(queryRegisterIds) > 0 {
 		// 获取汇总数据IDs, 用于查询合计数据
@@ -673,6 +674,7 @@ func (ct *InvoicePaymentController) List(c *gin.Context) {
 			return
 		}
 
+		//fmt.Println("summaryIds:",summaryIds)
 		var listErr, totalErr, totalGroupErr error
 		wg := sync.WaitGroup{}
 
@@ -808,6 +810,7 @@ func (ct *InvoicePaymentController) List(c *gin.Context) {
 				v.EndDate = utils.TimeTransferString(utils.FormatDate, registerList[i].EndDate)
 				v.ServicesName = servicesNameMap[registerList[i].ContractRegisterId]
 				v.InvoicePaymentList = summaryMap[registerList[i].SummaryId]
+				v.ContractType = registerList[i].ContractType
 				respList = append(respList, v)
 			}
 		}()

+ 11 - 3
controller/contract/pre_register.go

@@ -187,6 +187,7 @@ func (rg *PreRegisterController) Add(c *gin.Context) {
 	ob.ProductIds = req.ProductIds
 	ob.StartDate = startDate
 	ob.EndDate = endDate
+	ob.HasInvoice = 1
 	ob.Set()
 	ob.CurrencyUnit = currencyUnit
 	if req.RegisterType == fms.ContractInvoiceTypePreMake {
@@ -402,7 +403,6 @@ func (rg *PreRegisterController) Edit(c *gin.Context) {
 	if len(req.List) > 0 {
 		currencyUnit = req.List[0].CurrencyUnit
 	}
-
 	// 获取销售分组信息
 	sellerList, e := crmService.GetSellerDepartmentListWithGroupAndTeam()
 	if e != nil {
@@ -473,6 +473,7 @@ func (rg *PreRegisterController) Edit(c *gin.Context) {
 	}
 
 	invoiceList := make([]*fms.ContractInvoice, 0)
+	ppList := make([]*fms.ContractPreRegister, 0)
 	for _, r := range req.List {
 		// 货币及汇率
 		rateList, e := fmsService.GetTodayCurrencyRateList()
@@ -577,7 +578,7 @@ func (rg *PreRegisterController) Edit(c *gin.Context) {
 			//到款
 			pp.ArriveRemark = r.Remark
 			pp.ArriveDate = registerDate
-			pp.ArriveId = v.ContractRegisterId
+			pp.ArriveId = v.ContractInvoiceId
 			pp.ArriveOriginAmount = r.Amount
 			a, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", pp.ArriveOriginAmount/rate), 64)
 			pp.ArriveAmount = a
@@ -601,13 +602,14 @@ func (rg *PreRegisterController) Edit(c *gin.Context) {
 		}
 
 		invoiceList = append(invoiceList, v)
+		ppList = append(ppList, pp)
 	}
 	invoiceUpdateCols := []string{
 		"CurrencyUnit", "OriginAmount", "Amount", "InvoiceDate", "AdminId", "AdminName", "Remark",
 		"ServiceProductId", "StartDate", "EndDate", "ModifyTime",
 	}
 	// 更新合同登记、套餐、开票到款
-	if e = fms.UpdateContractPreRegister(ob, updateCols, serviceList, invoiceList, invoiceUpdateCols, req.DelInvoiceIds, req.DelPreRegisterIds); e != nil {
+	if e = fms.UpdateContractPreRegister(ob, updateCols, serviceList, invoiceList, invoiceUpdateCols, req.DelInvoiceIds, req.DelPreRegisterIds, ppList); e != nil {
 		resp.FailMsg("操作失败", "更新合同及套餐失败, Err: "+e.Error(), c)
 		return
 	}
@@ -689,6 +691,11 @@ func (rg *PreRegisterController) Del(c *gin.Context) {
 		return
 	}
 
+	e = fms.DeleteInvoicePaymentSummaryByInvoiceIdAndPaymentId(req.InvoiceId, req.ArriveId, req.ContractRegisterId)
+	if e != nil {
+		resp.FailMsg("删除统计记录失败", "Err:"+e.Error(), c)
+		return
+	}
 	//todo 合同看情况要不要删
 
 	resp.Ok("操作成功", c)
@@ -946,6 +953,7 @@ func (rg *PreRegisterController) Save(c *gin.Context) {
 	ob.StartDate = startDate
 	ob.EndDate = endDate
 	ob.ModifyTime = time.Now()
+	ob.CurrencyUnit = req.List[0].CurrencyUnit
 	if req.RegisterType == fms.ContractInvoiceTypePreMake {
 		//sellerItem := sellerMap[r.SellerId]
 		//if sellerItem == nil {

+ 84 - 49
controller/contract/register.go

@@ -54,7 +54,7 @@ func (rg *RegisterController) List(c *gin.Context) {
 
 	cond := `1 = 1`
 	pars := make([]interface{}, 0)
-	// 合同编号/客户姓名/销售/实际使用
+	// 合同编号/客户姓名/销售/代付
 	if req.Keyword != "" {
 		kw := "%" + req.Keyword + "%"
 		cond += ` AND (company_name LIKE ? OR contract_code LIKE ? OR seller_name LIKE ? OR rai_seller_name LIKE ? OR actual_company_name LIKE ?)`
@@ -962,11 +962,11 @@ func (rg *RegisterController) Detail(c *gin.Context) {
 	result.InvoiceList = make([]*fms.ContractInvoiceItem, 0)
 	result.PaymentList = make([]*fms.ContractInvoiceItem, 0)
 	for i := range invoiceList {
-		if invoiceList[i].InvoiceType == fms.ContractInvoiceTypeMake {
+		if invoiceList[i].InvoiceType == fms.ContractInvoiceTypeMake  || invoiceList[i].InvoiceType == fms.ContractInvoiceTypePreMake{
 			result.InvoiceList = append(result.InvoiceList, invoiceList[i])
 			continue
 		}
-		if invoiceList[i].InvoiceType == fms.ContractInvoiceTypePay {
+		if invoiceList[i].InvoiceType == fms.ContractInvoiceTypePay || invoiceList[i].InvoiceType == fms.ContractInvoiceTypePrePay{
 			result.PaymentList = append(result.PaymentList, invoiceList[i])
 		}
 	}
@@ -1555,9 +1555,9 @@ func (rg *RegisterController) Export(c *gin.Context) {
 	// 1行1列-右合并两格, 下合并1行
 	cell1 := titleRow.AddCell()
 	if req.ListParam == 0 {
-		cell1.HMerge = 8
+		cell1.HMerge = 9
 	} else {
-		cell1.HMerge = 7
+		cell1.HMerge = 9
 	}
 
 	cell1.VMerge = 1
@@ -1571,7 +1571,8 @@ func (rg *RegisterController) Export(c *gin.Context) {
 	titleRow.AddCell().SetString("")
 	titleRow.AddCell().SetString("")
 	titleRow.AddCell().SetString("")
-	hInt += 8
+	titleRow.AddCell().SetString("")
+	hInt += 9
 
 	if req.ListParam == 0 {
 		//如果是全部的话要多一格
@@ -1681,7 +1682,7 @@ func (rg *RegisterController) Export(c *gin.Context) {
 	row3Title := make([]string, 0)
 	row3TitleParent := make([]string, 0)
 	row3Title = append(row3Title, "客户名称", "新客户\n0-是\n1-否", "合同类型\n0-自付合同\n1-代付合同",
-		"合同子类型\n续约-0\n新签-1\n补充协议-2", "代付方", "关联主合同(补充协议)", "关联合同(代付合同)")
+		"合同子类型\n续约-0\n新签-1\n补充协议-2", "合同所属方", "代付方" ,"关联主合同(补充协议)", "关联合同(代付合同)")
 	if req.ListParam == 0 {
 		row3Title = append(row3Title, "FICC销售", "权益销售", "FICC大套餐")
 		for i := range permissionList {
@@ -1790,6 +1791,15 @@ func (rg *RegisterController) Export(c *gin.Context) {
 		dataRow.AddCell().SetString(newCompanyMap[v.NewCompany])
 		dataRow.AddCell().SetString(fmt.Sprint(contractTMap[v.HasPayment]))
 		dataRow.AddCell().SetString(fmt.Sprint(contractSubTMap[v.ContractType]))
+		if v.HasPayment == 1 {
+			if v.HasInvoice == 1 {
+				dataRow.AddCell().SetString("1")
+			} else {
+				dataRow.AddCell().SetString("0")
+			}
+		} else {
+			dataRow.AddCell().SetString("")
+		}
 		dataRow.AddCell().SetString(v.ActualPayCompanies)
 		dataRow.AddCell().SetString(v.RelateContractMainCode)
 		dataRow.AddCell().SetString(v.RelateContractCode)
@@ -1804,9 +1814,9 @@ func (rg *RegisterController) Export(c *gin.Context) {
 
 
 		if req.ListParam != 0 {
-			k += 9
-		} else {
 			k += 10
+		} else {
+			k += 11
 		}
 		// 大套餐
 		col4Name := row3Title[k]
@@ -1970,9 +1980,13 @@ func (rg *RegisterController) InvoiceList(c *gin.Context) {
 		pageIndex = 1
 	}
 
-	cond := `invoice_type = ?`
+	cond := ``
+	if req.InvoiceType == 1 {
+		cond = `invoice_type IN (1,3)`
+	} else {
+		cond = `invoice_type IN (2,4)`
+	}
 	pars := make([]interface{}, 0)
-	pars = append(pars, req.InvoiceType)
 	// 搜索
 	if req.Keyword != "" {
 		kw := fmt.Sprint("%", req.Keyword, "%")
@@ -2298,15 +2312,15 @@ func (rg *RegisterController) Import(c *gin.Context) {
 
 	//权益行业套餐名称
 	raiIndustryMap := map[int]string{
-		40: "医药",
-		41: "医药",
-		42: "消费",
-		43: "消费",
-		44: "科技",
-		45: "科技",
-		46: "智造",
-		48: "智造",
-		49: "策略",
+		43: "医药",
+		44: "医药",
+		45: "消费",
+		46: "消费",
+		47: "科技",
+		48: "科技",
+		49: "智造",
+		50: "智造",
+		51: "策略",
 	}
 
 	// 获取货币列表及汇率(汇率为导入日的汇率)
@@ -2387,36 +2401,42 @@ func (rg *RegisterController) Import(c *gin.Context) {
 						}
 						continue
 					} else if k == 4 {
+						if !strings.Contains(text, "合同所属方") {
+							resp.Fail("【合同所属方】列名称有误, 请参考模板导入", c)
+							return
+						}
+						continue
+					} else if k == 5 {
 						if text != "代付方" {
 							resp.Fail("【代付方】列名称有误, 请参考模板导入", c)
 							return
 						}
 						continue
-					} else if k == 5 {
-						if !strings.Contains(text, "关联主合同") {
+					} else if k == 6 {
+						if !strings.Contains(text, "关联主合同(补充协议)") {
 							resp.Fail("【关联主合同】列名称有误, 请参考模板导入", c)
 							return
 						}
 						continue
-					} else if k == 6 {
+					} else if k == 7 {
 						if !strings.Contains(text, "关联合同") {
 							resp.Fail("【关联合同】列名称有误, 请参考模板导入", c)
 							return
 						}
 						continue
-					} else if k == 7 {
+					} else if k == 8 {
 						if text != "FICC销售" {
 							resp.Fail("【FICC销售】列名称有误, 请参考模板导入", c)
 							return
 						}
 						continue
-					} else if k == 8 {
+					} else if k == 9 {
 						if text != "权益销售" {
 							resp.Fail("【权益销售】列名称有误, 请参考模板导入", c)
 							return
 						}
 						continue
-					} else if k == 9 {
+					} else if k == 10 {
 						if text != "FICC大套餐" {
 							resp.Fail("【FICC大套餐】列名称有误, 请参考模板导入", c)
 							return
@@ -2493,19 +2513,32 @@ func (rg *RegisterController) Import(c *gin.Context) {
 						continue
 					}
 					if k == 4 {
-						rowRegister.ActualPayCompanies = v
+						if rowRegister.HasPayment == 1{
+							if v == "0" {
+								//所属方为实际使用方,不走开票到款流程
+								rowRegister.HasInvoice = 0
+							} else if v == "1" {
+								rowRegister.HasInvoice = 1
+							}
+						} else {
+							rowRegister.HasInvoice = 1
+						}
 						continue
 					}
 					if k == 5 {
-						rowRegister.RelateContractMainCode = v
+						rowRegister.ActualPayCompanies = v
 						continue
 					}
 					if k == 6 {
+						rowRegister.RelateContractMainCode = v
+						continue
+					}
+					if k == 7 {
 						rowRegister.RelateContractCode = v
 						continue
 					}
 					// FICC销售
-					if k == 7 {
+					if k == 8 {
 						if v != "" {
 							/*resp.Fail(fmt.Sprintf("第%d行销售名称不可为空, 请按模板导入", i+1), c)
 							return*/
@@ -2521,7 +2554,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
 					}
 
 					// 权益销售
-					if k == 8 {
+					if k == 9 {
 						if v == "" && rowRegister.SellerName == "" {
 							resp.Fail(fmt.Sprintf("第FICC销售名称和权益销售名称不可都为空, 请按模板导入", i+1), c)
 							return
@@ -2536,7 +2569,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
 						continue
 					}
 					// FICC大套餐
-					if k == 9 {
+					if k == 10 {
 						if v == "是" {
 							tempItem := serviceTempNameMap[titleMap[k]]
 							if tempItem == nil {
@@ -2558,7 +2591,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
 						continue
 					}
 					// FICC小套餐
-					if k >= 10 && k <= 30 {
+					if k >= 11 && k <= 31 {
 						// 小套餐权限
 						if v == "是" {
 							rowChartPermissionIdArr = append(rowChartPermissionIdArr, strconv.Itoa(chartPermissionNameIdMap[titleMap[k]]))
@@ -2567,7 +2600,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
 						continue
 					}
 					// 其他类型套餐
-					if k >= 31 && k <= 37 {
+					if k >= 32 && k <= 38 {
 						if v == "是" {
 							tempItem := serviceTempNameMap[titleMap[k]]
 							if tempItem == nil {
@@ -2588,10 +2621,10 @@ func (rg *RegisterController) Import(c *gin.Context) {
 						}
 						continue
 					}
-					if k >= 38 && k <= 48 {
+					if k >= 39 && k <= 49 {
 						if v == "是" {
 							// 权益大套餐
-							if k <= 41 {
+							if k <= 42 {
 								//新增
 								parentName := "权益大套餐"
 								tempItem := serviceTempNameMap[titleMap[k]]
@@ -2627,6 +2660,8 @@ func (rg *RegisterController) Import(c *gin.Context) {
 								rootName := "行业套餐"
 								// 新增三条套餐信息
 								parentName, _ := raiIndustryMap[k]
+								fmt.Println("raiIndustryMap:", raiIndustryMap)
+								fmt.Println("titleMap:", titleMap)
 								childName := titleMap[k]
 								fullName := childName + "_" + parentName + "_" + rootName
 								if fullName != "" {
@@ -2686,7 +2721,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
 						continue
 					}
 					// 权益研选等套餐
-					if k >= 49 && k <= 53 {
+					if k >= 50 && k <= 54 {
 						if v == "是" {
 							tempItem := serviceTempNameMap[titleMap[k]]
 							if tempItem == nil {
@@ -2708,12 +2743,12 @@ func (rg *RegisterController) Import(c *gin.Context) {
 						continue
 					}
 					// 套餐备注
-					if k == 54 {
+					if k == 55 {
 						rowRegister.ServiceRemark = v
 						continue
 					}
 					// 开始时间/到期时间
-					if k == 57 {
+					if k == 58 {
 						// 转换失败可能是因为格式为Excel日期格式, 读取出来会是一串数字, 将其转换成日期字符串再处理
 						va := cell.Value
 						if va == "" {
@@ -2737,7 +2772,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
 						rowRegister.StartDate = startDate
 						continue
 					}
-					if k == 58 {
+					if k == 59 {
 						va := cell.Value
 						if va == "" {
 							resp.Fail(fmt.Sprintf("第%d行到期时间不可为空, 请按模板导入", i+1), c)
@@ -2760,7 +2795,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
 						continue
 					}
 					// 合同金额
-					if k == 59 {
+					if k == 60 {
 						amountStr := v
 						amount, e := strconv.ParseFloat(amountStr, 64)
 						if e != nil {
@@ -2771,7 +2806,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
 						continue
 					}
 					// 金额单位
-					if k == 60 {
+					if k == 61 {
 						rate := rateMap[v]
 						if rate <= 0 {
 							resp.Fail(fmt.Sprintf("第%d行金额单位有误, 请按模板导入", i+1), c)
@@ -2782,7 +2817,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
 						continue
 					}
 					// FICC 套餐总金额
-					if k == 61 {
+					if k == 62 {
 						amountStr := v
 						amount, e := strconv.ParseFloat(amountStr, 64)
 						if e != nil {
@@ -2801,7 +2836,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
 						continue
 					}
 					// 权益套餐总金额
-					if k == 62 {
+					if k == 63 {
 						amountStr := v
 						amount, e := strconv.ParseFloat(amountStr, 64)
 						if e != nil {
@@ -2820,12 +2855,12 @@ func (rg *RegisterController) Import(c *gin.Context) {
 						continue
 					}
 					// 约定付款日期
-					if k == 63 {
+					if k == 64 {
 						rowRegister.AgreedPayTime = v
 						continue
 					}
 					// 签订日
-					if k == 64 {
+					if k == 65 {
 						va := cell.Value
 						if va == "" {
 							continue
@@ -2847,7 +2882,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
 						continue
 					}
 					// 合同状态
-					if k == 65 {
+					if k == 66 {
 						rowRegister.ContractStatus = fms.ContractStatusNameKeyMap[v]
 						if rowRegister.ContractStatus == 0 {
 							resp.Fail(fmt.Sprintf("第%d行合同状态不匹配, 请按模板导入", i+1), c)
@@ -2856,7 +2891,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
 						continue
 					}
 					// 合同编号
-					if k == 66 {
+					if k == 67 {
 						rowContractCode := v
 						if rowContractCode == "" {
 							resp.Fail(fmt.Sprintf("第%d行合同编号不可为空, 请按模板导入", i+1), c)
@@ -2871,12 +2906,12 @@ func (rg *RegisterController) Import(c *gin.Context) {
 						continue
 					}
 					// 合规备注
-					if k == 67 {
+					if k == 68 {
 						rowRegister.Remark = v
 						continue
 					}
 					// 开票列表
-					k2 := 67
+					k2 := 68
 					for ir := 0; ir < invoiceMax; ir++ {
 						n := ir + 1
 						// 开票日

+ 6 - 0
models/fms/contract_invoice.go

@@ -344,6 +344,7 @@ type InvoicePaymentCensusItem struct {
 	StartDate          string                      `json:"start_date" description:"合同开始日期"`
 	EndDate            string                      `json:"end_date" description:"合同结束日期"`
 	ServicesName       string                      `json:"services_name" description:"套餐信息字符串拼接"`
+	ContractType       int                         `json:"contract_type" description:"合同类型: 0-无 1-新签; 2-续约"`
 	InvoicePaymentList []*InvoicePaymentCensusInfo `json:"invoice_payment_list" description:"开票到款列表"`
 }
 
@@ -590,3 +591,8 @@ type ContractInvoiceRespItem struct {
 	ContractInvoice
 	CompanyName string `gorm:"column:company_name" json:"company_name" description:"客户名称"`
 }
+
+func (c *ContractInvoice) FetchByRegisterId(registerId int) (items []*ContractInvoice, err error) {
+	err = global.DEFAULT_MYSQL.Model(c).Where("is_deleted = 0 AND contract_register_id = ?", registerId).Scan(&items).Error
+	return
+}

+ 45 - 2
models/fms/contract_register.go

@@ -1,6 +1,7 @@
 package fms
 
 import (
+	"fmt"
 	"hongze/fms_api/global"
 	"hongze/fms_api/models/base"
 	"hongze/fms_api/utils"
@@ -562,7 +563,7 @@ type CheckContractNameResp struct {
 
 // UpdateContractPreRegister 更新合同预登记
 func UpdateContractPreRegister(item *ContractRegister, updateCols []string, serviceDetail []*ContractServiceAndDetail,
-	invoiceList []*ContractInvoice, invoiceUpdateCols []string, delInvoiceIds, delPreRegisterIds []int) (err error) {
+	invoiceList []*ContractInvoice, invoiceUpdateCols []string, delInvoiceIds, delPreRegisterIds []int, ppList []*ContractPreRegister) (err error) {
 	tx := global.DEFAULT_MYSQL.Begin()
 	defer func() {
 		if err != nil {
@@ -619,6 +620,25 @@ func UpdateContractPreRegister(item *ContractRegister, updateCols []string, serv
 				err = e
 				return
 			}
+			if len(ppList) > 0 {
+				pp := &ContractPreRegister{
+					PreRegisterId: invoiceList[i].PreRegisterId,
+				}
+				fmt.Println("PreRegisterId:", pp.PreRegisterId)
+				fmt.Println("invoiceList[i].ContractInvoiceId:", invoiceList[i].ContractInvoiceId)
+				ppUpdateCols := make([]string, 0)
+				if invoiceList[i].InvoiceType == 3 {
+					pp.InvoiceId = invoiceList[i].ContractInvoiceId
+					ppUpdateCols = append(ppUpdateCols, "InvoiceId")
+				} else {
+					pp.ArriveId = invoiceList[i].ContractInvoiceId
+					ppUpdateCols = append(ppUpdateCols, "ArriveId")
+				}
+				if e := pp.Update(ppUpdateCols); e != nil {
+					err = e
+					return
+				}
+			}
 		} else {
 			if e := tx.Model(invoiceList[i]).Select(invoiceUpdateCols).Updates(invoiceList[i]).Error; e != nil {
 				err = e
@@ -710,6 +730,11 @@ func UpdateContractRegisterPre(item *ContractRegister, updateCols []string, serv
 		//}
 	}
 
+	productId := 0
+	if len(invoiceList) > 0 {
+		productId = invoiceList[0].ServiceProductId
+	}
+
 	//更新另一类型的invoice表数据
 	invoiceItem := ContractInvoice{
 		ContractRegisterId: item.ContractRegisterId,
@@ -717,7 +742,7 @@ func UpdateContractRegisterPre(item *ContractRegister, updateCols []string, serv
 		EndDate:            item.EndDate,
 		CurrencyUnit:       item.CurrencyUnit,
 	}
-	tx.Model(&invoiceItem).Select([]string{"StartDate", "EndDate", "CurrencyUnit"}).Where("ContractRegisterId", item.ContractRegisterId).Updates(invoiceItem)
+	tx.Model(&invoiceItem).Select([]string{"StartDate", "EndDate", "CurrencyUnit"}).Where("contract_register_id", item.ContractRegisterId).Updates(invoiceItem)
 
 	// 开票到款操作类型: 0-无; 1-更新; 2-新增;
 	if invoiceHandleType == 2 {
@@ -753,6 +778,24 @@ func UpdateContractRegisterPre(item *ContractRegister, updateCols []string, serv
 			}
 		}
 	}
+
+	pp := &ContractPreRegister{}
+	ppItem, e := pp.Fetch(ppList[0].PreRegisterId)
+	if e != nil {
+		err = e
+	}
+	//更新同一预登记记录下的productid
+	otherInvoiceItem := ContractInvoice{
+		ServiceProductId: productId,
+	}
+	if ppList[0].InvoiceType == 3 {
+		otherInvoiceItem.ContractInvoiceId = ppItem.ArriveId
+	} else {
+		otherInvoiceItem.ContractInvoiceId = ppItem.InvoiceId
+	}
+
+	tx.Model(&otherInvoiceItem).Select([]string{"ServiceProductId"}).Updates(otherInvoiceItem)
+
 	return
 }
 

+ 7 - 0
models/fms/invoice_payment_summary.go

@@ -155,3 +155,10 @@ func DeleteInvoicePaymentSummaryByRegisterId(registerId int) (err error) {
 	err = global.DEFAULT_MYSQL.Exec(sql, registerId).Error
 	return
 }
+
+// DeleteInvoicePaymentSummaryByInvoiceIdAndPaymentId 根据开票到款ID删除汇总数据
+func DeleteInvoicePaymentSummaryByInvoiceIdAndPaymentId(invoiceId, arriveId, registerId int) (err error) {
+	sql := `DELETE FROM invoice_payment_summary WHERE invoice_id = ? AND payment_id = ? AND register_id = ?`
+	err = global.DEFAULT_MYSQL.Exec(sql, invoiceId, arriveId, registerId).Error
+	return
+}

+ 14 - 0
services/fms/invoice_payment.go

@@ -182,6 +182,7 @@ func SummaryInvoicePaymentByContractRegisterId(registerId int) {
 	ficcPaymentIds := make([]int, 0)
 	raiInvoiceIds := make([]int, 0)
 	raiPaymentIds := make([]int, 0)
+	noProductPaymentIds := make([]int, 0)
 	for i := range list {
 		if list[i].InvoiceType == fms.ContractInvoiceTypeMake {
 			if list[i].ServiceProductId == crm.CompanyProductFicc {
@@ -212,6 +213,8 @@ func SummaryInvoicePaymentByContractRegisterId(registerId int) {
 				ficcPaymentIds = append(ficcPaymentIds, list[i].ContractInvoiceId)
 			} else if list[i].ServiceProductId == crm.CompanyProductRai {
 				raiPaymentIds = append(raiPaymentIds, list[i].ContractInvoiceId)
+			} else {
+				noProductPaymentIds = append(noProductPaymentIds, list[i].ContractInvoiceId)
 			}
 			continue
 		}
@@ -220,6 +223,7 @@ func SummaryInvoicePaymentByContractRegisterId(registerId int) {
 	raiInvoiceLen := len(raiInvoiceIds)
 	ficcPaymentLen := len(ficcPaymentIds)
 	raiPaymentLen := len(raiPaymentIds)
+	noProductPaymentLen := len(noProductPaymentIds)
 
 	// 汇总数据
 	nowTime := time.Now().Local()
@@ -287,6 +291,16 @@ func SummaryInvoicePaymentByContractRegisterId(registerId int) {
 			summaryList = append(summaryList, v)
 		}
 	}
+	if noProductPaymentLen > 0 {
+		for i := range noProductPaymentIds {
+			v := new(fms.InvoicePaymentSummary)
+			v.RegisterId = registerId
+			v.PaymentId = noProductPaymentIds[i]
+			v.CreateTime = nowTime
+			v.ModifyTime = nowTime
+			summaryList = append(summaryList, v)
+		}
+	}
 
 	// 删除并新增汇总数据
 	summaryOB := new(fms.InvoicePaymentSummary)