Explorar el Código

Merge branch 'fms_2.9'

zwxi hace 1 año
padre
commit
53bdbaf361

+ 135 - 68
controller/census/invoice_payment.go

@@ -1050,6 +1050,9 @@ func getCensusIncomeListV2(ch chan models.CensusIncomeChartResp, req fms.IncomeL
 	} else if req.CompanyType == 2 {
 		cond += ` AND b.contract_type IN (2,3,4) `
 		historyCond += ` AND new_company = 0 `
+	} else if req.CompanyType == 3 {
+		cond += ` AND b.contract_type = 1 `
+		historyCond += ` AND new_company = 1 `
 	}
 
 	var latestTime time.Time
@@ -1302,16 +1305,16 @@ func getCensusIncomeListV2(ch chan models.CensusIncomeChartResp, req fms.IncomeL
 
 		}
 
-		{ //去年同期,用于计算同比值
-			prevSt := fmt.Sprint(prevStartDate, " 00:00:00")
-			prevEd := fmt.Sprint(prevEndDate, " 23:59:59")
+		{ // 去年同期,用于计算同比值
+			prevSt := fmt.Sprint(prevStartDate, " 00:00:00") // 格式化上一年同一天的开始时间
+			prevEd := fmt.Sprint(prevEndDate, " 23:59:59")   // 格式化上一年同一天的结束时间
 
-			//校验日期,分段查询
+			// 校验日期,分段查询
 			if prevStartDateTime.After(historyTime) || prevStartDateTime.Equal(historyTime) {
-				//全部走新查询
-				prevCond += ` AND ((b.invoice_time BETWEEN ? AND ?) or (d.invoice_time BETWEEN ? AND ?))`
-				prevPars = append(prevPars, prevSt, prevEd, prevSt, prevEd)
-				prevSummaryIds, e := fms.GetInvoicePaymentCensusSummaryDataIds(prevCond, prevPars)
+				// 全部走新查询
+				prevCond += ` AND ((b.invoice_time BETWEEN ? AND ?) or (d.invoice_time BETWEEN ? AND ?))` // 查询条件加入新的时间范围
+				prevPars = append(prevPars, prevSt, prevEd, prevSt, prevEd)                               // 添加时间参数到参数列表
+				prevSummaryIds, e := fms.GetInvoicePaymentCensusSummaryDataIds(prevCond, prevPars)        // 获取摘要ID列表
 				if e != nil {
 					return
 				}
@@ -1320,20 +1323,20 @@ func getCensusIncomeListV2(ch chan models.CensusIncomeChartResp, req fms.IncomeL
 				var prevAmountTotal float64
 
 				if len(prevSummaryIds) > 0 {
-					amountCond := `a.id IN ? `
+					amountCond := `a.id IN ? ` // 查询条件为ID在给定的摘要ID列表中
 					amountPars := make([]interface{}, 0)
-					amountPars = append(amountPars, prevSummaryIds)
+					amountPars = append(amountPars, prevSummaryIds) // 将摘要ID列表添加到参数列表
 					if req.SellerIds != "" {
 						sellerIds := strings.Split(req.SellerIds, ",")
 						amountCond += ` AND (( b.seller_id IN ? AND a.invoice_id <> 0 AND b.invoice_time BETWEEN ? AND ?)`
-						amountCond += `OR ( d.seller_id IN ? AND  a.payment_id <> 0 AND a.invoice_id = 0 AND d.invoice_time BETWEEN ? AND ?)) `
-						amountPars = append(amountPars, sellerIds, prevSt, prevEd, sellerIds, prevSt, prevEd)
+						amountCond += `OR ( d.seller_id IN ? AND  a.payment_id <> 0 AND a.invoice_id = 0 AND d.invoice_time BETWEEN ? AND ?)) ` // 根据卖家ID和发票/支付状态筛选时间范围
+						amountPars = append(amountPars, sellerIds, prevSt, prevEd, sellerIds, prevSt, prevEd)                                   // 将卖家ID列表添加到参数列表
 					} else {
 						amountCond += ` AND ((a.invoice_id <> 0 AND b.invoice_time BETWEEN ? AND ?)`
-						amountCond += `OR (a.payment_id <> 0 AND a.invoice_id = 0 AND d.invoice_time BETWEEN ? AND ?))`
+						amountCond += `OR (a.payment_id <> 0 AND a.invoice_id = 0 AND d.invoice_time BETWEEN ? AND ?))` // 根据发票/支付状态筛选时间范围
 						amountPars = append(amountPars, prevSt, prevEd)
 					}
-					results, e := fms.GetContractSummaryIncomeAmount(amountCond, amountPars)
+					results, e := fms.GetContractSummaryIncomeAmount(amountCond, amountPars) // 获取合同摘要收入金额数据
 					if e != nil {
 						err = fmt.Errorf("获取汇总数据失败, Err: %s", e.Error())
 						return
@@ -1341,35 +1344,35 @@ func getCensusIncomeListV2(ch chan models.CensusIncomeChartResp, req fms.IncomeL
 					var amountSum float64
 					//historydataList = append(historydataList, results...)
 					for _, result := range results {
-						amountSum += result.Amount
+						amountSum += result.Amount // 累计收入金额
 					}
-					prevAmountTotal, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", amountSum), 64)
-					historyAccumulate += prevAmountTotal
-					partHistoryAccumulate += prevAmountTotal
+					prevAmountTotal, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", amountSum), 64) // 将累计金额转换为浮点数
+					historyAccumulate += prevAmountTotal                                        // 累计历史金额
+					partHistoryAccumulate += prevAmountTotal                                    // 累计部分历史金额
 				}
 				if i == j || i == numMonth {
 					if req.ListParam == "4" {
-						prevTotalMoneySlice = append(prevTotalMoneySlice, historyAccumulate)
+						prevTotalMoneySlice = append(prevTotalMoneySlice, historyAccumulate) // 将累计金额添加到总金额切片中
 						if prevStartDateTime.Month() == 12 {
-							historyAccumulate = 0
+							historyAccumulate = 0 // 如果是去年的12月份,则将历史金额清零
 						}
 					} else if req.ListParam == "0" {
-						prevTotalMoneySlice = append(prevTotalMoneySlice, prevAmountTotal)
+						prevTotalMoneySlice = append(prevTotalMoneySlice, prevAmountTotal) // 将部分历史金额添加到总金额切片中
 					} else if i > 0 || i == numMonth {
-						prevTotalMoneySlice = append(prevTotalMoneySlice, partHistoryAccumulate)
+						prevTotalMoneySlice = append(prevTotalMoneySlice, partHistoryAccumulate) // 将部分历史金额添加到总金额切片中
 						fmt.Println("partHistoryAccumulate:", partHistoryAccumulate)
-						partHistoryAccumulate = 0.0
+						partHistoryAccumulate = 0.0 // 清零部分历史金额
 					}
 				}
 			} else if prevEndDateTime.Before(historyTime) || prevEndDateTime.Equal(historyTime) {
-				//全部走旧查询
+				// 全部走旧查询
 				fmt.Println("prevSt:", prevSt)
 				fmt.Println("prevEd:", prevEd)
-				prevHistoryCond += ` AND (invoice_time BETWEEN ? AND ?)`
-				prevHistoryPars = append(prevHistoryPars, prevSt, prevEd)
+				prevHistoryCond += ` AND (invoice_time BETWEEN ? AND ?)`  // 查询条件加入旧的时间范围
+				prevHistoryPars = append(prevHistoryPars, prevSt, prevEd) // 添加时间参数到参数列表
 				// 开票到款金额合计(换算后)
 				var amountTotal float64
-				results, e := fms.GetIncomeHistory(prevHistoryCond, prevHistoryPars)
+				results, e := fms.GetIncomeHistory(prevHistoryCond, prevHistoryPars) // 获取历史收入数据
 				if e != nil {
 					err = fmt.Errorf("获取汇总数据失败, Err: %s", e.Error())
 					return
@@ -1377,42 +1380,69 @@ func getCensusIncomeListV2(ch chan models.CensusIncomeChartResp, req fms.IncomeL
 				//historydataList = append(historydataList, results...)
 				var amountSum float64
 				for _, result := range results {
-					amountSum += result.Amount
+					amountSum += result.Amount // 累计收入金额
 				}
-				amountTotal, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", amountSum), 64)
-				historyAccumulate += amountTotal
-				partHistoryAccumulate += amountTotal
+				amountTotal, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", amountSum), 64) // 将累计金额转换为浮点数
+				historyAccumulate += amountTotal                                        // 累计历史金额
+				partHistoryAccumulate += amountTotal                                    // 累计部分历史金额
 
 				if i == j || i == numMonth {
 					if req.ListParam == "4" {
-						prevTotalMoneySlice = append(prevTotalMoneySlice, historyAccumulate)
+						prevTotalMoneySlice = append(prevTotalMoneySlice, historyAccumulate) // 将累计金额添加到总金额切片中
 						if prevStartDateTime.Month() == 12 {
-							historyAccumulate = 0
+							historyAccumulate = 0 // 如果是去年的12月份,则将历史金额清零
 						}
 					} else if req.ListParam == "0" {
-						prevTotalMoneySlice = append(prevTotalMoneySlice, amountTotal)
+						prevTotalMoneySlice = append(prevTotalMoneySlice, amountTotal) // 将历史金额添加到总金额切片中
 					} else if i > 0 || i == numMonth {
-						prevTotalMoneySlice = append(prevTotalMoneySlice, partHistoryAccumulate)
+						prevTotalMoneySlice = append(prevTotalMoneySlice, partHistoryAccumulate) // 将部分历史金额添加到总金额切片中
 						fmt.Println("partHistoryAccumulate:", partHistoryAccumulate)
-						partHistoryAccumulate = 0.0
+						partHistoryAccumulate = 0.0 // 清零部分历史金额
 					}
 				}
-				//fmt.Println("partHistoryAccumulate:",partHistoryAccumulate)
+				if req.ListParam == "1" && i == j {
+					if i == 0 {
+						dateSlice = append(dateSlice, startDateTime.AddDate(0, 2, 0).Format("06/01")) // 添加下一个月份的开始日期到日期切片中
+						j = j + 2
+					} else {
+						dateSlice = append(dateSlice, startDateTime.AddDate(0, 3, 0).Format("06/01")) // 添加下一季度的开始日期到日期切片中
+						j = j + 3
+					}
+				} else if req.ListParam == "2" && i == j {
+					if i == 0 {
+						dateSlice = append(dateSlice, startDateTime.AddDate(0, 5, 0).Format("06/01")) // 添加下五个月份的开始日期到日期切片中
+						j = j + 5
+					} else {
+						dateSlice = append(dateSlice, startDateTime.AddDate(0, 6, 0).Format("06/01")) // 添加下半年的开始日期到日期切片中
+						j = j + 6
+					}
+				} else if req.ListParam == "3" && i == j {
+					if i == 0 {
+						dateSlice = append(dateSlice, startDateTime.AddDate(0, 11, 0).Format("06/01")) // 添加下十一个月份的开始日期到日期切片中
+						j = j + 11
+					} else {
+						dateSlice = append(dateSlice, startDateTime.AddDate(0, 12, 0).Format("06/01")) // 添加下一季度的开始日期到日期切片中
+						j = j + 12
+					}
+				} else if i == j {
+					dateSlice = append(dateSlice, startDateTime.Format("06/01")) // 添加当月开始日期到日期切片中
+					j++
+				}
 			}
 			if req.ListParam == "1" && i == j {
 				if i == 0 {
-					dateSlice = append(dateSlice, startDateTime.AddDate(0, 2, 0).Format("06/01"))
+					dateSlice = append(dateSlice, startDateTime.AddDate(0, 2, 0).Format("06/01")) // 添加下一个月份的开始日期到日期切片中
 					j = j + 2
 				} else {
-					dateSlice = append(dateSlice, startDateTime.AddDate(0, 3, 0).Format("06/01"))
+					dateSlice = append(dateSlice, startDateTime.AddDate(0, 3, 0).Format("06/01")) // 添加下一季度的开始日期到日期切片中
 					j = j + 3
 				}
 			} else if req.ListParam == "2" && i == j {
 				if i == 0 {
-					dateSlice = append(dateSlice, startDateTime.AddDate(0, 5, 0).Format("06/01"))
+					dateSlice = append(dateSlice, startDateTime.AddDate(0, 5, 0).Format("06/01")) // 添加下五个月份的开始日期到日期切片中
 					j = j + 5
 				} else {
-					dateSlice = append(dateSlice, startDateTime.AddDate(0, 6, 0).Format("06/01"))
+					dateSlice = append(dateSlice, startDateTime.AddDate(0, 6, 0).Format("06/01")) // 添加下半年的开始日期到日期切片中
 					j = j + 6
 				}
 			} else if req.ListParam == "3" && i == j {
@@ -1433,27 +1463,64 @@ func getCensusIncomeListV2(ch chan models.CensusIncomeChartResp, req fms.IncomeL
 	fmt.Println("prevTotalMoneySlice:", len(prevTotalMoneySlice))
 	fmt.Println("totalMoneySlice:", len(totalMoneySlice))
 
-	//计算同比值
-	for i := range prevTotalMoneySlice {
-		var yoy float64
-		var yoyStr string
-		//fmt.Println("1:", prevTotalMoneySlice[i])
-		//fmt.Println("2:", totalMoneySlice[i])
-		//fmt.Println("3:", totalMoneySlice[i]-prevTotalMoneySlice[i])
-		totalMoneySlice[i], _ = strconv.ParseFloat(fmt.Sprintf("%.2f", totalMoneySlice[i]), 64)
-		if prevTotalMoneySlice[i] != 0 && totalMoneySlice[i] != 0 {
-			yoy = (totalMoneySlice[i] - prevTotalMoneySlice[i]) / prevTotalMoneySlice[i]
-			yoyStr = fmt.Sprintf("%.4f", yoy)
-
-			if i == len(prevTotalMoneySlice)-1 && i > 0 && req.ListParam == "3" {
-				fmt.Println("totalMoneySlice[i-1]:", totalMoneySlice[i-1])
-				yoy = (totalMoneySlice[i] - totalMoneySlice[i-1]) / totalMoneySlice[i-1]
+
+	if req.CompanyType != 3 {
+		//计算同比值
+		for i := range prevTotalMoneySlice {
+			var yoy float64
+			var yoyStr string
+			//fmt.Println("1:", prevTotalMoneySlice[i])
+			//fmt.Println("2:", totalMoneySlice[i])
+			//fmt.Println("3:", totalMoneySlice[i]-prevTotalMoneySlice[i])
+			totalMoneySlice[i], _ = strconv.ParseFloat(fmt.Sprintf("%.2f", totalMoneySlice[i]), 64)
+			if prevTotalMoneySlice[i] != 0 && totalMoneySlice[i] != 0 {
+				yoy = (totalMoneySlice[i] - prevTotalMoneySlice[i]) / prevTotalMoneySlice[i]
 				yoyStr = fmt.Sprintf("%.4f", yoy)
+
+				if i == len(prevTotalMoneySlice)-1 && i > 0 && req.ListParam == "3" {
+					fmt.Println("totalMoneySlice[i-1]:", totalMoneySlice[i-1])
+					yoy = (totalMoneySlice[i] - totalMoneySlice[i-1]) / totalMoneySlice[i-1]
+					yoyStr = fmt.Sprintf("%.4f", yoy)
+				}
+			}
+			yoySlice = append(yoySlice, yoyStr)
+		}
+	} else {
+		// 当筛选条件是”月度“时,并且客户是”未续约“客户,展示柱形图和曲线图
+		// 当筛选条件是”季度“、”半年度“、”年度“、”月度统计“时,并且客户是”未续约“时,仅展示柱形图,无曲线图
+		// 未续约客户收入:去年同期老客户收入金额  减  当期老客户收入金额
+		// 移动平均值:若是10月份,计算8月,9月,10月,这三个月的收入金额平均值
+		if req.ListParam == "0" {
+			for i := range prevTotalMoneySlice {
+				totalMoneySlice[i], _ = strconv.ParseFloat(fmt.Sprintf("%.2f", prevTotalMoneySlice[i] - totalMoneySlice[i] ), 64)
+				var yoy float64
+				var yoyStr string
+				if i > 1 {
+					// 前俩月没有
+					//fmt.Println("1:", prevTotalMoneySlice[i])
+					//fmt.Println("2:", totalMoneySlice[i])
+					//fmt.Println("3:", totalMoneySlice[i]-prevTotalMoneySlice[i])
+					//if prevTotalMoneySlice[i] != 0 && totalMoneySlice[i] != 0 {
+					//	yoy = (totalMoneySlice[i] - prevTotalMoneySlice[i]) / prevTotalMoneySlice[i]
+					//	yoyStr = fmt.Sprintf("%.4f", yoy)
+					//
+					//	if i == len(prevTotalMoneySlice)-1 && i > 0 && req.ListParam == "3" {
+					//		fmt.Println("totalMoneySlice[i-1]:", totalMoneySlice[i-1])
+					//		yoy = (totalMoneySlice[i] - totalMoneySlice[i-1]) / totalMoneySlice[i-1]
+					//		yoyStr = fmt.Sprintf("%.4f", yoy)
+					//	}
+					//}
+					yoy = (totalMoneySlice[i] + totalMoneySlice[i-1] + totalMoneySlice[i-2]) / 3
+					yoyStr = fmt.Sprintf("%.4f", yoy)
+					yoySlice = append(yoySlice, yoyStr)
+				} else {
+					yoySlice = append(yoySlice, "")
+				}
 			}
 		}
-		yoySlice = append(yoySlice, yoyStr)
 	}
 
+
 	incomeChart.Title = "开票到款统计图"
 	incomeChart.Date = dateSlice
 	incomeChart.TotalMoney = totalMoneySlice
@@ -1710,7 +1777,7 @@ func (ct *InvoicePaymentController) NotInvoiceList(c *gin.Context) {
 
 			// 获取未进行过开票到款的合同数据,其实只用到了合同id和ProductIds用来补充不同的套餐信息
 			noSummaryCond += ` AND b.is_deleted = 0 AND b.contract_status <> 4 `
-			if len(notQueryRegisterIds) >0 {
+			if len(notQueryRegisterIds) > 0 {
 				noSummaryCond += ` AND b.contract_register_id IN ? AND b.contract_register_id NOT IN ?`
 				noSummaryPars = append(noSummaryPars, queryRegisterIds, notQueryRegisterIds)
 			} else {
@@ -1846,7 +1913,6 @@ func (ct *InvoicePaymentController) NotInvoiceList(c *gin.Context) {
 				unitMap[currencyList[i].Code] = currencyList[i].UnitName
 			}
 
-
 			for registerId, list := range NotInvoiceSummaryMap {
 				for _, v := range list {
 					//fmt.Println("v.ContractRegisterId", v.ContractRegisterId)
@@ -1856,8 +1922,8 @@ func (ct *InvoicePaymentController) NotInvoiceList(c *gin.Context) {
 					if v.NotInvoicedAmountTotal == 0 {
 						if v.InvoiceAmountTotal > v.PaymentAmountTotal {
 							// 有合规登记或补录合同过的,有serviceAmountMap信息
-							if _,ok := serviceAmountMap[registerId]; ok {
-								if _,ok2 := serviceAmountMap[registerId][v.ServiceProductId]; ok2{
+							if _, ok := serviceAmountMap[registerId]; ok {
+								if _, ok2 := serviceAmountMap[registerId][v.ServiceProductId]; ok2 {
 									v.NotInvoicedAmountTotal = serviceAmountMap[registerId][v.ServiceProductId].ServiceAmount - v.InvoiceAmountTotal
 								}
 							} else {
@@ -1865,9 +1931,9 @@ func (ct *InvoicePaymentController) NotInvoiceList(c *gin.Context) {
 								v.NotInvoicedAmountTotal = v.InvoiceAmountTotal - v.PaymentAmountTotal
 							}
 						} else {
-							if _,ok := serviceAmountMap[registerId]; ok {
+							if _, ok := serviceAmountMap[registerId]; ok {
 								// 有合规登记或补录合同过的,有serviceAmountMap信息
-								if _,ok2 := serviceAmountMap[registerId][v.ServiceProductId]; ok2{
+								if _, ok2 := serviceAmountMap[registerId][v.ServiceProductId]; ok2 {
 									v.NotInvoicedAmountTotal = serviceAmountMap[registerId][v.ServiceProductId].ServiceAmount - v.PaymentAmountTotal
 								}
 							} else {
@@ -2287,6 +2353,7 @@ func (ct *InvoicePaymentController) NotPaymentList(c *gin.Context) {
 				v.ContractAmount = registerList[i].ContractAmount
 				v.UnitName = unitMap[registerList[i].CurrencyUnit]
 				v.ProductIds = registerList[i].ProductIds
+				v.NotInvoiceTotal = registerList[i].ContractAmount - registerList[i].InvoicedAmount
 				respList = append(respList, v)
 			}
 		}()
@@ -2716,12 +2783,12 @@ func ExportNotPaymentCensusList(c *gin.Context, results *fms.NotInvoicePaymentCe
 		// 开票到款信息
 		for _, v2 := range v.InvoicePaymentList {
 			rowData := []string{
-				v2.InvoiceDate,               // 开票日
+				v2.InvoiceDate,                  // 开票日
 				fmt.Sprint(v2.NotPaymentAmount), // 开票金额
-				v2.UnitName,                  // 开票金额
-				v2.SellerName,                // 销售
-				v2.SellerGroupName,           // 组别
-				sellerTypeMap[v2.SellerType], // 销售类型
+				v2.UnitName,                     // 开票金额
+				v2.SellerName,                   // 销售
+				v2.SellerGroupName,              // 组别
+				sellerTypeMap[v2.SellerType],    // 销售类型
 			}
 			for i := range rowData {
 				dataRow.AddCell().SetString(rowData[i])

+ 34 - 2
controller/census/seller.go

@@ -58,8 +58,11 @@ func (ct *SellerController) GroupInvoiceList(c *gin.Context) {
 	}
 	outCond := ` department_id = %d AND parent_id = 0 `
 	outCond = fmt.Sprintf(outCond, departmentId)
-	cond := ` (invoice_type = %d OR invoice_type = %d) AND is_deleted = 0 AND seller_group_id != 0 `
+	cond := ` (invoice_type = %d OR invoice_type = %d) AND a.is_deleted = 0 AND a.seller_group_id != 0 `
 	cond = fmt.Sprintf(cond, fms.ContractInvoiceTypeMake, fms.ContractInvoiceTypePreMake)
+
+	//adminCond := ` (invoice_type = %d OR invoice_type = %d) AND is_deleted = 0 AND seller_group_id != 0 `
+	//adminCond = fmt.Sprintf(cond, fms.ContractInvoiceTypeMake, fms.ContractInvoiceTypePreMake)
 	pars := make([]interface{}, 0)
 	// 开票日期
 	if req.StartDate != "" && req.EndDate != "" {
@@ -67,6 +70,17 @@ func (ct *SellerController) GroupInvoiceList(c *gin.Context) {
 		ed := fmt.Sprint(req.EndDate, " 23:59:59")
 		cond += ` AND (invoice_time BETWEEN '%s' AND '%s')`
 		cond = fmt.Sprintf(cond, st, ed)
+
+		//adminCond += ` AND (invoice_time BETWEEN '%s' AND '%s')`
+		//adminCond = fmt.Sprintf(cond, st, ed)
+	}
+
+	if req.CompanyType == 1 {
+		cond += ` AND b.contract_type = 1 `
+		//historyCond += ` AND new_company = 1 `
+	} else if req.CompanyType == 2 {
+		cond += ` AND b.contract_type IN (2,3,4) `
+		//historyCond += ` AND new_company = 0 `
 	}
 
 	page := new(base.Page)
@@ -250,6 +264,8 @@ func (ct *SellerController) InvoiceList(c *gin.Context) {
 		resp.Fail("请选择正确的销售类型", c)
 		return
 	}
+
+
 	pars := make([]interface{}, 0)
 	adminPars := make([]interface{}, 0)
 	outCond := ` a.department_id = %d `
@@ -259,6 +275,10 @@ func (ct *SellerController) InvoiceList(c *gin.Context) {
 	totalCond := ` department_id = %d `
 	totalCond = fmt.Sprintf(totalCond, departmentId)
 	totalPars := make([]interface{}, 0)
+
+	if !req.ShowResign {
+		adminCond += ` AND enabled = 1 `
+	}
 	if req.GroupId > 0 {
 		// 筛选组别时, 查询当前组别的下级组(因为admin表存的group_id, 有三级的存的是子ID, 只有二级的存的才是父ID =_=!)
 		groupCond := `parent_id = ?`
@@ -282,13 +302,25 @@ func (ct *SellerController) InvoiceList(c *gin.Context) {
 		totalCond += ` AND group_id IN (?) `
 		totalPars = append(totalPars, groupIds)
 	}
-	sumCond := ` (invoice_type = ? OR invoice_type = ? ) AND is_deleted = 0 AND seller_id != 0 `
+
+
+
+	sumCond := ` (invoice_type = ? OR invoice_type = ? ) AND a.is_deleted = 0 AND a.seller_id != 0 `
 	sumPars := make([]interface{}, 0)
 	sumPars = append(sumPars, fms.ContractInvoiceTypeMake, fms.ContractInvoiceTypePreMake)
 	cond := ` (c.invoice_type = %d OR c.invoice_type = %d) AND c.is_deleted = 0 AND c.seller_id != 0 `
 	inCond := ` (invoice_type = %d OR invoice_type = %d) AND is_deleted = 0 AND seller_id != 0 `
 	cond = fmt.Sprintf(cond, fms.ContractInvoiceTypeMake, fms.ContractInvoiceTypePreMake)
 	inCond = fmt.Sprintf(inCond, fms.ContractInvoiceTypeMake, fms.ContractInvoiceTypePreMake)
+
+	if req.CompanyType == 1 {
+		cond += ` AND b.contract_type = 1 `
+		//historyCond += ` AND new_company = 1 `
+	} else if req.CompanyType == 2 {
+		cond += ` AND b.contract_type IN (2,3,4) `
+		//historyCond += ` AND new_company = 0 `
+	}
+
 	// 开票日期
 	if req.StartDate != "" && req.EndDate != "" {
 		st := fmt.Sprint(req.StartDate, " 00:00:00")

+ 1 - 1
controller/crm/contract.go

@@ -142,7 +142,7 @@ func (rg *ContractController) SearchList(c *gin.Context) {
 		respList = append(respList, respItem)
 
 	}
-
+	
 	page.SetTotal(total)
 	baseData := new(base.BaseData)
 	baseData.SetPage(page)

+ 15 - 16
models/crm/contract.go

@@ -76,24 +76,23 @@ type ContractSearchListReq struct {
 
 // ContractSearchListResp CRM系统合同-搜索列表响应体
 type ContractSearchListResp struct {
-	ContractId      int     `json:"contract_id" description:"合同ID"`
-	ContractCode    string  `json:"contract_code" description:"合同编号"`
-	ProductId       int     `json:"product_id" description:"产品ID"`
-	CompanyName     string  `json:"company_name" description:"客户名称"`
-	//PayContractCode string  `json:"pay_contract_code" description:"代付合同编号"`
-	RelateContractCode string `json:"relate_contract_code" description:"代付合同关联的实际使用方合同编号"`
-	//PayCompanyName  string  `json:"pay_company_name" description:"代付客户名称"`
-	ActualCompanyName string `json:"actual_company_name" description:"实际使用方"`
-	SellerId        int     `json:"seller_id" description:"销售ID"`
-	SellerName      string  `json:"seller_name" description:"销售名称"`
-	ContractTypeKey int     `json:"contract_type_key" description:"FMS合同类型: 1-新签; 2-续约; 3-代付; 4-补充协议;"`
-	ContractType    string  `json:"contract_type" description:"CRM合同类型: 新签合同; 续约合同; 补充协议;"`
+	ContractId         int     `json:"contract_id" description:"合同ID"`
+	ContractCode       string  `json:"contract_code" description:"合同编号"`
+	ProductId          int     `json:"product_id" description:"产品ID"`
+	CompanyName        string  `json:"company_name" description:"客户名称"`
+	RelateContractCode string  `json:"relate_contract_code" description:"代付合同关联的实际使用方合同编号"`
+	ActualCompanyName  string  `json:"actual_company_name" description:"实际使用方"`
+	SellerId           int     `json:"seller_id" description:"销售ID"`
+	SellerName         string  `json:"seller_name" description:"销售名称"`
+	ContractTypeKey    int     `json:"contract_type_key" description:"FMS合同类型: 1-新签; 2-续约; 3-代付; 4-补充协议;"`
+	ContractType       string  `json:"contract_type" description:"CRM合同类型: 新签合同; 续约合同; 补充协议;"`
+	Price              float64 `json:"price" description:"合同金额"`
+	StartDate          string  `json:"start_date" description:"合同开始日期"`
+	EndDate            string  `json:"end_date" description:"合同结束日期"`
+	ActualPayCompanies string  `json:"actual_pay_companies" description:"该合同关联的所有代付方, 英文逗号拼接"`
 	ContractTypeInt    int  `json:"contract_type_int" description:"CRM合同类型: 1新签合同; 2续约合同; 3补充协议;"`
 	ContractBusinessTypeInt    int  `json:"contract_business_type_int" description:"合同业务类型,1'业务合同', 2'代付合同;"`
-	Price           float64 `json:"price" description:"合同金额"`
-	StartDate       string  `json:"start_date" description:"合同开始日期"`
-	EndDate         string  `json:"end_date" description:"合同结束日期"`
-	ActualPayCompanies string  `json:"actual_pay_companies" description:"该合同关联的所有代付方, 英文逗号拼接"`
+	
 }
 
 // PayCompanyRelation 代付合同

+ 18 - 13
models/fms/contract_invoice.go

@@ -93,8 +93,8 @@ func (c *ContractInvoice) Delete() (err error) {
 
 func (c *ContractInvoice) Sum(field, condition string, pars []interface{}) (total float64, err error) {
 	totalList := make([]float64, 0)
-	err = global.DEFAULT_MYSQL.Model(c).
-		Where("is_deleted = 0").
+	err = global.DEFAULT_MYSQL.Table("contract_invoice AS a").Joins("INNER JOIN contract_register AS b ON a.contract_register_id = b.contract_register_id ").
+		Where("a.is_deleted = 0").
 		Where(condition, pars...).
 		Pluck(field, &totalList).Error
 	for i := range totalList {
@@ -403,6 +403,7 @@ type CensusSellerGroupInvoiceListReq struct {
 	SortType   int    `json:"sort_type" form:"sort_type" description:"排序方式: 1-正序; 2-倒序"`
 	IsExport   int    `json:"is_export" form:"is_export" description:"是否导出: 0-否; 1-是"`
 	SellerType int    `json:"seller_type" form:"seller_type" description:"销售类型:1ficc销售,2权益销售"`
+	CompanyType int    `json:"company_type" form:"company_type" description:"客户类型 0全部 1新客户 2老客户"`
 	base.PageReq
 }
 
@@ -449,6 +450,8 @@ type CensusSellerInvoiceListReq struct {
 	SortType   int    `json:"sort_type" form:"sort_type" description:"排序方式: 1-正序; 2-倒序"`
 	IsExport   int    `json:"is_export" form:"is_export" description:"是否导出: 0-否; 1-是"`
 	SellerType int    `json:"seller_type" form:"seller_type" description:"销售类型:1ficc销售,2权益销售"`
+	ShowResign bool   `json:"show_resign" form:"show_resign" description:"是否显示离职销售"`
+	CompanyType int    `json:"company_type" form:"company_type" description:"客户类型 0全部 1新客户 2老客户"`
 	base.PageReq
 }
 
@@ -614,14 +617,14 @@ func (c *ContractInvoice) FetchByRegisterId(registerId int) (items []*ContractIn
 }
 
 // GetDuplicateContractInvoiceDetailItemListWithType 预登记列表详情用-获取开票到款列表
-func GetDuplicateContractInvoiceDetailItemListWithType(companyName, startDate, endDate string,contractType, hasPayment int) (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) " +
+		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
@@ -664,7 +667,7 @@ type IncomeListReq struct {
 	EndDate     string `json:"end_date" form:"end_date" binding:"omitempty,datetime=2006-01" description:"结束日期"`
 	IsExport    int    `json:"is_export" form:"is_export" description:"是否导出: 0-否; 1-是"`
 	ListParam   string `json:"list_param" form:"list_param" description:"套餐类型: 0-月度; 1-季度; 2-半年度;3-年度;4-月度累计"`
-	CompanyType int    `json:"company_type" form:"company_type" description:"客户类型 0全部 1新客户 2老客户"`
+	CompanyType int    `json:"company_type" form:"company_type" description:"客户类型 0全部 1新客户 2老客户 3未续约"`
 }
 
 // 获取最新的开票或到款日期
@@ -723,17 +726,18 @@ type NotPaymentCensusInfo struct {
 }
 
 // GetCensusSellerGroupInvoicePageListV2 获取销售组开票统计列表-分页
-func GetCensusSellerGroupInvoicePageListV2(page base.IPage,groupStr, condition string, pars []interface{}, amountSum float64) (count int, results []*CensusSellerGroupInvoiceItem, err error) {
+func GetCensusSellerGroupInvoicePageListV2(page base.IPage, groupStr, condition string, pars []interface{}, amountSum float64) (count int, results []*CensusSellerGroupInvoiceItem, err error) {
 	sql := ` 
 				SELECT
 					seller_group_id AS group_id,
 					SUM(amount) AS invoice_amount,
 					SUM(amount) / %f AS group_rate
 				FROM
-					contract_invoice
+					contract_invoice AS a
+				INNER JOIN contract_register AS b ON a.contract_register_id = b.contract_register_id 
 				WHERE
 					%s
-				AND seller_group_id IN (`+groupStr+`)
+				AND seller_group_id IN (` + groupStr + `)
 				GROUP BY
 					seller_group_id  ORDER BY %s LIMIT %d,%d
 			`
@@ -743,7 +747,7 @@ func GetCensusSellerGroupInvoicePageListV2(page base.IPage,groupStr, condition s
 					contract_invoice
 				WHERE
 					%s
-				AND seller_group_id IN (`+groupStr+`)
+				AND seller_group_id IN (` + groupStr + `)
 				GROUP BY
 					seller_group_id  )as a
 			`
@@ -764,14 +768,15 @@ func GetCensusSellerInvoicePageListV2(page base.IPage, adminStr, inCond, conditi
 				) AS group_rate,
 				SUM(c.amount) / %f AS seller_rate
 				FROM contract_invoice AS c 
+				INNER JOIN contract_register AS b ON c.contract_register_id = b.contract_register_id 
 				WHERE %s
-				AND c.seller_id IN (`+adminStr+`)
+				AND c.seller_id IN (` + adminStr + `)
 				GROUP BY c.seller_id ORDER BY %s LIMIT %d,%d `
 
 	sqlCount := ` select count(1) as count from (SELECT * 
 				FROM contract_invoice AS c
 				WHERE %s
-				AND c.seller_id IN (`+adminStr+`) GROUP BY c.seller_id ) as a
+				AND c.seller_id IN (` + adminStr + `) GROUP BY c.seller_id ) as a
 				 `
 	sqlCount = fmt.Sprintf(sqlCount, condition)
 	err = global.DEFAULT_MYSQL.Raw(sqlCount, pars...).Find(&count).Error
@@ -812,4 +817,4 @@ func GetInvoiceCountByRegisterId(registerId int) (total int64, err error) {
 	err = global.DEFAULT_MYSQL.Table("contract_invoice as a ").
 		Where("is_deleted = 0 AND contract_register_id = ?", registerId).Count(&total).Error
 	return
-}
+}

+ 3 - 2
models/fms/contract_register.go

@@ -41,8 +41,8 @@ type ContractRegister struct {
 	HasPayment             int       `gorm:"column:has_payment" json:"has_payment" description:"是否有代付: 0-无; 1-有"`
 	HasInvoice             int       `gorm:"column:has_invoice" json:"has_invoice" description:"是否需要开票到款: 0-无; 1-有"`
 	NewCompany             int       `gorm:"column:new_company" json:"new_company" description:"是否为新客户: 0-否; 1-是"`
+	ActualPayCompanies string    `gorm:"column:actual_pay_companies" json:"actual_pay_companies" description:"合同关联的所有代付方名称, 英文逗号拼接"`
 	IsDeleted              int       `gorm:"column:is_deleted" json:"is_deleted" description:"是否已删除: 0-正常; 1-已删除"`
-	ActualPayCompanies     string    `gorm:"column:actual_pay_companies" json:"actual_pay_companies" description:"合同关联的所有代付方名称, 英文逗号拼接"`
 	base.TimeBase
 }
 
@@ -195,7 +195,7 @@ type ContractRegisterAddReq struct {
 	ContractRegisterId     int                           `json:"contract_register_id" description:"登记ID"`
 	Services               []ContractServiceAddReq       `json:"services" description:"服务套餐内容"`
 	ServiceAmount          []ContractServiceAmountAddReq `json:"service_amount" description:"服务套餐金额"`
-	ActualPayCompanies     string                        `json:"actual_pay_companies" description:"合同关联的所有代付方名称, 英文逗号拼接"`
+	ActualPayCompanies string                  `json:"actual_pay_companies" description:"合同关联的所有代付方名称, 英文逗号拼接"`
 }
 
 // ContractRegisterEditReq 编辑合同登记请求体
@@ -707,6 +707,7 @@ func UpdateContractPreRegister(item *ContractRegister, updateCols []string, serv
 	return
 }
 
+
 // UpdateContractRegister 预登记保存和更新
 func UpdateContractRegisterPre(item *ContractRegister, updateCols []string, serviceDetail []*ContractServiceAndDetail,
 	invoiceList []*ContractInvoice, invoiceUpdateCols []string, invoiceHandleType int, ppList []*ContractPreRegister) (err error) {