Selaa lähdekoodia

Merge branch 'fms_2.7' into debug

# Conflicts:
#	controller/contract/register.go
#	models/fms/invoice_payment_summary.go
ziwen 1 vuosi sitten
vanhempi
commit
b1142d99a0

+ 65 - 53
controller/contract/register.go

@@ -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  || invoiceList[i].InvoiceType == fms.ContractInvoiceTypePreMake{
+		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 || invoiceList[i].InvoiceType == fms.ContractInvoiceTypePrePay{
+		if invoiceList[i].InvoiceType == fms.ContractInvoiceTypePay || invoiceList[i].InvoiceType == fms.ContractInvoiceTypePrePay {
 			result.PaymentList = append(result.PaymentList, invoiceList[i])
 		}
 	}
@@ -1091,6 +1091,7 @@ func (rg *RegisterController) Invoice(c *gin.Context) {
 
 	noChangeInvoiceIds := make([]int, 0)
 	newInvoice := make([]*fms.ContractInvoice, 0)
+	sellerMap := make(map[int]*crm.SellerAdminWithGroupTeam)
 	if len(req.AmountList) > 0 {
 		// 合同有效时长(计算付款方式)
 		dayDiff := item.EndDate.Sub(item.StartDate).Hours() / 24
@@ -1101,7 +1102,6 @@ func (rg *RegisterController) Invoice(c *gin.Context) {
 			resp.FailData("获取销售失败", "Err:"+e.Error(), c)
 			return
 		}
-		sellerMap := make(map[int]*crm.SellerAdminWithGroupTeam)
 		for i := range sellerList {
 			sellerMap[sellerList[i].SellerId] = sellerList[i]
 		}
@@ -1255,6 +1255,31 @@ func (rg *RegisterController) Invoice(c *gin.Context) {
 		return
 	}
 
+	//如果是开票,强制修改到款记录的销售
+	if len(newInvoice) > 0 && req.InvoiceType == fms.ContractInvoiceTypeMake {
+		invoiceItem, err := fms.GetContractInvoiceByRegisterIdAndType(req.ContractRegisterId)
+		if err != nil {
+			resp.FailMsg("获取到款数据失败", "获取到款数据失败, Err: "+err.Error(), c)
+			return
+		}
+		sellerItem := sellerMap[newInvoice[0].SellerId]
+		if sellerItem == nil {
+			resp.Fail("销售信息异常", c)
+			return
+		}
+		invoiceItem.SellerId = sellerItem.SellerId
+		invoiceItem.SellerName = sellerItem.SellerName
+		invoiceItem.SellerGroupId = sellerItem.GroupId
+		invoiceItem.SellerGroupName = sellerItem.GroupName
+		invoiceItem.SellerTeamId = sellerItem.TeamId
+		invoiceItem.SellerTeamName = sellerItem.TeamName
+		e = invoiceItem.Update([]string{"SellerId","SellerName","SellerGroupId","SellerGroupName","SellerTeamId","SellerTeamName"})
+		if e != nil {
+			resp.FailMsg("更新到款销售失败", "更新到款销售失败, Err: "+e.Error(), c)
+			return
+		}
+	}
+
 	// todo 判断是否符合均分金额的条件,如果符合,需要生成金额分配记录表
 	if req.InvoiceType == fms.ContractInvoiceTypePay {
 		err = fmsService.CalculatePaymentServiceAmount(req.ContractRegisterId)
@@ -1693,7 +1718,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 {
@@ -1814,16 +1839,15 @@ func (rg *RegisterController) Export(c *gin.Context) {
 		dataRow.AddCell().SetString(v.ActualPayCompanies)
 		dataRow.AddCell().SetString(v.RelateContractMainCode)
 		dataRow.AddCell().SetString(v.RelateContractCode)
-		if req.ListParam == 0{
+		if req.ListParam == 0 {
 			dataRow.AddCell().SetString(v.SellerName)
 			dataRow.AddCell().SetString(v.RaiSellerName)
-		} else if req.ListParam == 1{
+		} else if req.ListParam == 1 {
 			dataRow.AddCell().SetString(v.SellerName)
 		} else {
 			dataRow.AddCell().SetString(v.RaiSellerName)
 		}
 
-
 		if req.ListParam != 0 {
 			k += 10
 		} else {
@@ -1890,13 +1914,13 @@ func (rg *RegisterController) Export(c *gin.Context) {
 		dataRow.AddCell().SetString(v.CurrencyUnit)                                      // 货币单位
 		if ficcAmount != nil {
 			dataRow.AddCell().SetString(fmt.Sprint("¥", ficcAmount.ServiceAmount)) // FICC套餐总金额
-			if raiAmount == nil{
-				dataRow.AddCell().SetString("")                                        // 权益套餐总金额
+			if raiAmount == nil {
+				dataRow.AddCell().SetString("") // 权益套餐总金额
 			}
 		}
 		if raiAmount != nil {
-			if ficcAmount == nil{
-				dataRow.AddCell().SetString("")                                       // 权益套餐总金额
+			if ficcAmount == nil {
+				dataRow.AddCell().SetString("") // 权益套餐总金额
 			}
 			dataRow.AddCell().SetString(fmt.Sprint("¥", raiAmount.ServiceAmount)) // FICC套餐总金额
 		}
@@ -2383,6 +2407,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
 	for _, sheet := range xlFile.Sheets {
 		// 遍历行读取
 		maxRow := sheet.MaxRow
+		fmt.Println("maxRow", maxRow)
 		for i := 0; i < maxRow; i++ {
 			// 第三行开始读取表头
 			if i == 2 {
@@ -2529,7 +2554,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
 						continue
 					}
 					if k == 4 {
-						if rowRegister.HasPayment == 1{
+						if rowRegister.HasPayment == 1 {
 							if v == "0" {
 								//所属方为实际使用方,不走开票到款流程
 								rowRegister.HasInvoice = 0
@@ -2812,7 +2837,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
 						continue
 					}
 					// 合同金额
-					if k == 58 {
+					if k == 60 {
 						amountStr := v
 						amount, e := strconv.ParseFloat(amountStr, 64)
 						if e != nil {
@@ -2823,7 +2848,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
 						continue
 					}
 					// 金额单位
-					if k == 59 {
+					if k == 61 {
 						rate := rateMap[v]
 						if rate <= 0 {
 							resp.Fail(fmt.Sprintf("第%d行金额单位有误, 请按模板导入", i+1), c)
@@ -2834,54 +2859,42 @@ func (rg *RegisterController) Import(c *gin.Context) {
 						continue
 					}
 					// FICC 套餐总金额
-					if k == 60 {
+					if k == 62 {
 						amountStr := v
-						if v != ""{
-							amount, e := strconv.ParseFloat(amountStr, 64)
-							if e != nil {
-								resp.Fail(fmt.Sprintf("第%d行FICC套餐总金额有误, 请按模板导入", i+1), c)
-								return
-							}
-							if amount > 0 {
-								tmp := &fms.ContractServiceAmount{
-									ProductId:     crm.CompanyProductFicc,
-									ServiceAmount: amount,
-									CurrencyUnit:  rowRegister.CurrencyUnit,
-									TimeBase:      base.TimeBase{},
-								}
-								rowServiceAmount = append(rowServiceAmount, tmp)
+						amount, _ := strconv.ParseFloat(amountStr, 64)
+						if amount > 0 {
+							tmp := &fms.ContractServiceAmount{
+								ProductId:     crm.CompanyProductFicc,
+								ServiceAmount: amount,
+								CurrencyUnit:  rowRegister.CurrencyUnit,
+								TimeBase:      base.TimeBase{},
 							}
-							continue
+							rowServiceAmount = append(rowServiceAmount, tmp)
 						}
+						continue
 					}
 					// 权益套餐总金额
-					if k == 61 {
+					if k == 63 {
 						amountStr := v
-						if v != ""{
-							amount, e := strconv.ParseFloat(amountStr, 64)
-							if e != nil {
-								resp.Fail(fmt.Sprintf("第%d行权益套餐总金额有误, 请按模板导入", i+1), c)
-								return
-							}
-							if amount > 0 {
-								tmp := &fms.ContractServiceAmount{
-									ProductId:     crm.CompanyProductRai,
-									ServiceAmount: amount,
-									CurrencyUnit:  rowRegister.CurrencyUnit,
-									TimeBase:      base.TimeBase{},
-								}
-								rowServiceAmount = append(rowServiceAmount, tmp)
+						amount, _ := strconv.ParseFloat(amountStr, 64)
+						if amount > 0 {
+							tmp := &fms.ContractServiceAmount{
+								ProductId:     crm.CompanyProductRai,
+								ServiceAmount: amount,
+								CurrencyUnit:  rowRegister.CurrencyUnit,
+								TimeBase:      base.TimeBase{},
 							}
-							continue
+							rowServiceAmount = append(rowServiceAmount, tmp)
 						}
+						continue
 					}
 					// 约定付款日期
-					if k == 62 {
+					if k == 64 {
 						rowRegister.AgreedPayTime = v
 						continue
 					}
 					// 签订日
-					if k == 63 {
+					if k == 65 {
 						va := cell.Value
 						if va == "" {
 							continue
@@ -2903,7 +2916,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
 						continue
 					}
 					// 合同状态
-					if k == 64 {
+					if k == 66 {
 						rowRegister.ContractStatus = fms.ContractStatusNameKeyMap[v]
 						if rowRegister.ContractStatus == 0 {
 							resp.Fail(fmt.Sprintf("第%d行合同状态不匹配, 请按模板导入", i+1), c)
@@ -2912,7 +2925,7 @@ func (rg *RegisterController) Import(c *gin.Context) {
 						continue
 					}
 					// 合同编号
-					if k == 65 {
+					if k == 67 {
 						rowContractCode := v
 						if rowContractCode == "" {
 							resp.Fail(fmt.Sprintf("第%d行合同编号不可为空, 请按模板导入", i+1), c)
@@ -2927,12 +2940,12 @@ func (rg *RegisterController) Import(c *gin.Context) {
 						continue
 					}
 					// 合规备注
-					if k == 66 {
+					if k == 68 {
 						rowRegister.Remark = v
 						continue
 					}
 					// 开票列表
-					k2 := 66
+					k2 := 68
 					for ir := 0; ir < invoiceMax; ir++ {
 						n := ir + 1
 						// 开票日
@@ -3283,7 +3296,6 @@ func (rg *RegisterController) CheckContractName(c *gin.Context) {
 	return
 }
 
-
 // CheckContract
 // @Title 货币单位列表
 // @Description 货币单位列表

+ 5 - 0
models/fms/contract_invoice.go

@@ -618,4 +618,9 @@ func GetDuplicateContractInvoiceDetailItemList(companyName, startDate, endDate s
 	}
 	itemList = formatContractInvoice2DetailItemList(list)
 	return
+}
+
+func GetContractInvoiceByRegisterIdAndType(registerId int) (items *ContractInvoice, err error) {
+	err = global.DEFAULT_MYSQL.Model(ContractInvoice{}).Where("is_deleted = 0 AND contract_register_id = ? AND invoice_type = 2", registerId).Order("create_time DESC").First(&items).Error
+	return
 }

+ 7 - 0
models/fms/invoice_payment_summary.go

@@ -244,3 +244,10 @@ type NotInvoicePaymentCensusResp struct {
 	NotInvoiceTotal         float64                     `json:"not_invoice_total" description:"未开票总金额(换算后)"`
 	NotInvoiceCurrencyTotal []*InvoiceListCurrencyTotal `json:"not_invoice_currency_total" description:"未开票-分币种总金额"`
 }
+
+// GetInvoicePaymentSummaryByRegisterIdAndInvoiceId 根据合同登记ID和开票ID获取汇总数据
+func GetInvoicePaymentSummaryByRegisterIdAndInvoiceId(registerId,invocieId int) (results []*ContractRegisterSummary, err error) {
+	sql := `SELECT * FROM invoice_payment_summary WHERE register_id = ? AND invoice_id= ? `
+	err = global.DEFAULT_MYSQL.Exec(sql, registerId, invocieId).Find(&results).Error
+	return
+}