瀏覽代碼

Merge branch 'fms_2.8' into debug

ziwen 1 年之前
父節點
當前提交
4c673a340f

+ 13 - 145
controller/census/invoice_payment.go

@@ -431,7 +431,11 @@ func ExportInvoicePaymentCensusList(c *gin.Context, results *fms.InvoicePaymentC
 		// 是否新客户
 		colC := dataRow.AddCell()
 		colC.VMerge = mergeRowNum
-		colC.SetString(newCompanyMap[v.NewCompany])
+		newCompany := 0
+		if v.ContractType == 1 {
+			newCompany = 1
+		}
+		colC.SetString(newCompanyMap[newCompany])
 		// 合同有效期
 		colD := dataRow.AddCell()
 		colD.VMerge = mergeRowNum
@@ -1166,8 +1170,8 @@ func getCensusIncomeListV2(ch chan models.CensusIncomeChartResp, req fms.IncomeL
 					amountCond := `a.id IN ? AND (a.invoice_id <> 0 OR (a.payment_id <> 0 AND a.invoice_id =0))`
 					amountPars := make([]interface{}, 0)
 					amountPars = append(amountPars, summaryIds)
-					amountCond += ` AND (b.invoice_time BETWEEN ? AND ?)`
-					amountPars = append(amountPars, st, ed)
+					amountCond += ` AND (b.invoice_time BETWEEN ? AND ?) OR (d.invoice_time BETWEEN ? AND ?)`
+					amountPars = append(amountPars, st, ed, st, ed)
 					results, e := fms.GetContractSummaryIncomeAmount(amountCond, amountPars)
 					if e != nil {
 						err = fmt.Errorf("获取汇总数据失败, Err: %s", e.Error())
@@ -1233,59 +1237,6 @@ func getCensusIncomeListV2(ch chan models.CensusIncomeChartResp, req fms.IncomeL
 
 				//fmt.Println("partAccumulate:",partAccumulate)
 			}
-			//else {
-			//	//刚好跨过20230301的,各查一部分
-			//	//fmt.Println("查询3")
-			//	var historyAmountTotal float64
-			//	histrtyCond += ` AND (invoice_time BETWEEN ? AND '2023-03-01 23:59:59' ) `
-			//	historyPars = append(historyPars, st)
-			//	//// 开票到款金额合计(换算后)
-			//	var amountTotal float64
-			//	results, e := fms.GetIncomeHistory(histrtyCond, historyPars)
-			//	if e != nil {
-			//		err = fmt.Errorf("获取汇总数据失败, Err: %s", e.Error())
-			//		return
-			//	}
-			//	var amountSum float64
-			//	for _, result := range results {
-			//		incomeChart.DataList = append(incomeChart.DataList, result)
-			//		amountSum += result.Amount
-			//	}
-			//	amountTotal, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", amountSum), 64)
-			//	accumulate += amountTotal
-			//	historyAmountTotal = amountTotal
-			//
-			//	cond += ` AND ((c.invoice_time BETWEEN '2023-03-02 00:00:00' AND ?) or (d.invoice_time BETWEEN '2023-03-02 00:00:00' AND ?))`
-			//	pars = append(pars, ed, ed)
-			//	summaryIds, e := fms.GetInvoicePaymentCensusSummaryDataIds(cond, pars)
-			//	if e != nil {
-			//		return
-			//	}
-			//
-			//	if len(summaryIds) > 0 {
-			//		amountCond := `a.id IN ? AND (a.invoice_id <> 0 OR (a.payment_id <> 0 AND a.invoice_id =0))`
-			//		amountPars := make([]interface{}, 0)
-			//		amountPars = append(amountPars, summaryIds)
-			//		results, e := fms.GetContractSummaryIncomeAmount(amountCond, amountPars)
-			//		if e != nil {
-			//			err = fmt.Errorf("获取汇总数据失败, Err: %s", e.Error())
-			//			return
-			//		}
-			//		var amountSum float64
-			//		for _, result := range results {
-			//			incomeChart.DataList = append(incomeChart.DataList, result)
-			//			amountSum += result.Amount
-			//		}
-			//		amountTotal, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", amountSum), 64)
-			//		accumulate += amountTotal
-			//	}
-			//	if req.ListParam == "4" {
-			//		totalMoneySlice = append(totalMoneySlice, accumulate)
-			//	} else {
-			//		totalMoneySlice = append(totalMoneySlice, amountTotal+historyAmountTotal)
-			//	}
-			//
-			//}
 
 		}
 
@@ -1310,7 +1261,7 @@ func getCensusIncomeListV2(ch chan models.CensusIncomeChartResp, req fms.IncomeL
 					amountCond := `a.id IN ? AND (a.invoice_id <> 0 OR (a.payment_id <> 0 AND a.invoice_id =0))`
 					amountPars := make([]interface{}, 0)
 					amountPars = append(amountPars, prevSummaryIds)
-					amountCond += ` AND (b.invoice_time BETWEEN ? AND ?)`
+					amountCond += ` AND (b.invoice_time BETWEEN ? AND ?) OR (d.invoice_time BETWEEN ? AND ?)`
 					amountPars = append(amountPars, prevSt, prevEd)
 					results, e := fms.GetContractSummaryIncomeAmount(amountCond, amountPars)
 					if e != nil {
@@ -1372,58 +1323,6 @@ func getCensusIncomeListV2(ch chan models.CensusIncomeChartResp, req fms.IncomeL
 				}
 				//fmt.Println("partHistoryAccumulate:",partHistoryAccumulate)
 			}
-			//else {
-			//	//刚好跨过20230301的,各查一部分
-			//	var historyAmountTotal float64
-			//	prevHistoryCond += ` AND (invoice_time BETWEEN ? AND '2023-03-01 23:59:59' ) `
-			//	prevHistoryPars = append(prevHistoryPars, prevSt)
-			//	// 开票到款金额合计(换算后)
-			//	var amountTotal float64
-			//	results, e := fms.GetIncomeHistory(prevHistoryCond, prevHistoryPars)
-			//	if e != nil {
-			//		err = fmt.Errorf("获取汇总数据失败, Err: %s", e.Error())
-			//		return
-			//	}
-			//	var amountSum float64
-			//	for _, result := range results {
-			//		amountSum += result.Amount
-			//	}
-			//	amountTotal, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", amountSum), 64)
-			//	historyAccumulate += amountTotal
-			//
-			//
-			//	prevCond += ` AND ((c.invoice_time BETWEEN '2023-03-02 00:00:00' AND ?) or (d.invoice_time BETWEEN '2023-03-02 00:00:00' AND ?))`
-			//	prevPars = append(prevPars, prevEd, prevEd)
-			//	prevSummaryIds, e := fms.GetInvoicePaymentCensusSummaryDataIds(prevCond, prevPars)
-			//	if e != nil {
-			//		return
-			//	}
-			//
-			//	// 开票到款金额合计(换算后)
-			//	var prevAmountTotal float64
-			//
-			//	if len(prevSummaryIds) > 0 {
-			//		amountCond := `a.id IN ? AND (a.invoice_id <> 0 OR (a.payment_id <> 0 AND a.invoice_id =0))`
-			//		amountPars := make([]interface{}, 0)
-			//		amountPars = append(amountPars, prevSummaryIds)
-			//		results, e := fms.GetContractSummaryIncomeAmount(amountCond, amountPars)
-			//		if e != nil {
-			//			err = fmt.Errorf("获取汇总数据失败, Err: %s", e.Error())
-			//			return
-			//		}
-			//		var amountSum float64
-			//		for _, result := range results {
-			//			amountSum += result.Amount
-			//		}
-			//		prevAmountTotal, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", amountSum), 64)
-			//		historyAccumulate += prevAmountTotal
-			//	}
-			//	if req.ListParam == "4" {
-			//		prevTotalMoneySlice = append(prevTotalMoneySlice, historyAccumulate)
-			//	} else {
-			//		prevTotalMoneySlice = append(prevTotalMoneySlice, prevAmountTotal+historyAmountTotal)
-			//	}
-			//}
 			if req.ListParam == "1" && i == j {
 				if i == 0{
 					dateSlice = append(dateSlice, startDateTime.AddDate(0, 2, 0).Format("06/01"))
@@ -1454,41 +1353,6 @@ func getCensusIncomeListV2(ch chan models.CensusIncomeChartResp, req fms.IncomeL
 			}
 		}
 	}
-	//for i, v := range dataList {
-	//	amountTotal, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", v.Amount), 64)
-	//	accumulate += amountTotal
-	//
-	//	if req.ListParam == "4" {
-	//		totalMoneySlice = append(totalMoneySlice, accumulate)
-	//	} else {
-	//		totalMoneySlice = append(totalMoneySlice, amountTotal)
-	//	}
-	//	if req.ListParam == "1" {
-	//		i = i + 2
-	//	} else if req.ListParam == "2" {
-	//		i = i + 5
-	//	} else if req.ListParam == "3" {
-	//		i = i + 11
-	//	}
-	//}
-	//
-	//for i, v := range historydataList {
-	//	historyAmountTotal, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", v.Amount), 64)
-	//	historyAccumulate += historyAmountTotal
-	//
-	//	if req.ListParam == "4" {
-	//		prevTotalMoneySlice = append(prevTotalMoneySlice, historyAccumulate)
-	//	} else {
-	//		prevTotalMoneySlice = append(prevTotalMoneySlice, historyAmountTotal)
-	//	}
-	//	if req.ListParam == "1" {
-	//		i = i + 2
-	//	} else if req.ListParam == "2" {
-	//		i = i + 5
-	//	} else if req.ListParam == "3" {
-	//		i = i + 11
-	//	}
-	//}
 
 	fmt.Println("prevTotalMoneySlice:", len(prevTotalMoneySlice))
 	fmt.Println("totalMoneySlice:", len(totalMoneySlice))
@@ -1568,7 +1432,11 @@ func ExportIncomeList(c *gin.Context, list []*fms.IncomeSummaryItem) {
 	for _, v := range incomeSummaryItemList {
 		dataRow := sheet.AddRow()
 		dataRow.AddCell().SetString(v.InvoiceDate.Format(utils.FormatDate)) // 开票日期
-		dataRow.AddCell().SetString(strconv.Itoa(v.NewCompany))             // 新客户
+		newCompany := 0
+		if v.ContractType == 1 {
+			newCompany = 1
+		}
+		dataRow.AddCell().SetString(strconv.Itoa(newCompany))             // 新客户
 		dataRow.AddCell().SetString(v.CompanyName)                          // 客户名称
 		dataRow.AddCell().SetString(fmt.Sprint(v.Amount))                   // 金额
 		dataRow.AddCell().SetString(v.SellerName)                           // 销售员

+ 2 - 2
controller/contract/register.go

@@ -2167,7 +2167,7 @@ func (rg *RegisterController) Export(c *gin.Context) {
 		row2NameKeyMap[row3Title[i]] = i
 	}
 
-	newCompanyMap := map[int]string{0: "1", 1: "0"}
+	newCompanyMap := map[int]string{2: "1", 1: "0"}
 	contractTMap := map[int]int{
 		fms.ContractTypeSelf:   0,
 		fms.ContractTypebehalf: 1,
@@ -2182,7 +2182,7 @@ func (rg *RegisterController) Export(c *gin.Context) {
 		dataRow := sheet.AddRow()
 		dataRow.SetHeight(20)
 		dataRow.AddCell().SetString(v.CompanyName)
-		dataRow.AddCell().SetString(newCompanyMap[v.NewCompany])
+		dataRow.AddCell().SetString(newCompanyMap[v.ContractType])
 		dataRow.AddCell().SetString(fmt.Sprint(contractTMap[v.HasPayment]))
 		dataRow.AddCell().SetString(fmt.Sprint(contractSubTMap[v.ContractType]))
 		if v.HasPayment == 1 {

+ 1 - 1
models/fms/contract_income_history.go

@@ -29,7 +29,7 @@ func (c *ContractIncomeHistory) TableName() string {
 
 // GetInvoicePaymentSummaryByRegisterIdAndInvoiceId 根据合同登记ID和开票ID获取汇总数据
 func GetIncomeHistory(condition string, pars []interface{}) (results []*IncomeSummaryItem, err error) {
-	sql := `SELECT amount,seller_name,new_company,company_name,invoice_time AS invoice_date FROM contract_income_history WHERE  `
+	sql := `SELECT amount,seller_name,new_company AS contract_type,company_name,invoice_time AS invoice_date FROM contract_income_history WHERE  `
 	sql += condition
 	sql += ` ORDER BY invoice_date `
 	err = global.DEFAULT_MYSQL.Raw(sql, pars...).Find(&results).Error

+ 4 - 5
models/fms/invoice_payment_summary.go

@@ -257,7 +257,7 @@ func GetInvoicePaymentSummaryByRegisterIdAndInvoiceId(registerId, invocieId int)
 
 type IncomeSummaryItem struct {
 	CompanyName string    `json:"company_name" description:"客户名称"`
-	NewCompany  int       `json:"new_company" description:"是否为新客户: 0-否; 1-是"`
+	ContractType  int       `json:"contract_type" description:"是否为新客户: 2-否; 1-是"`
 	InvoiceDate time.Time `json:"invoice_time" description:"开票日期"`
 	Amount      float64   `json:"amount" description:"金额"`
 	SellerName  string    `json:"seller_name" description:"销售名称"`
@@ -265,11 +265,10 @@ type IncomeSummaryItem struct {
 
 // GetContractSummaryIncomeAmount 获取汇总金额合计信息
 func GetContractSummaryIncomeAmount(condition string, pars []interface{}) (results []*IncomeSummaryItem, err error) {
-	joinCond := ` (a.invoice_id = b.contract_invoice_id OR a.payment_id = b.contract_invoice_id) `
-
 	query := global.DEFAULT_MYSQL.Table("invoice_payment_summary AS a").
-		Select("b.amount,b.invoice_time AS invoice_date , c.new_company,c.company_name,b.seller_name").
-		Joins(fmt.Sprintf(" JOIN contract_invoice AS b ON %s AND b.is_deleted = 0 ", joinCond)).
+		Select("IF(a.invoice_id=0,d.amount, b.amount) AS amount,IF(a.invoice_id=0,d.invoice_time, b.invoice_time) AS invoice_date, c.contract_type,c.company_name,IF(a.invoice_id=0,d.seller_name, b.seller_name) AS seller_name").
+		Joins("LEFT JOIN contract_invoice AS b ON a.invoice_id = b.contract_invoice_id AND b.is_deleted = 0 ").
+		Joins("LEFT JOIN contract_invoice AS d ON a.payment_id = d.contract_invoice_id AND d.is_deleted = 0").
 		Joins("JOIN contract_register AS c ON a.register_id = c.contract_register_id AND c.is_deleted = 0").
 		Where(condition, pars...).Group("id").Order("invoice_date ")
 	//nq := global.DEFAULT_MYSQL.Table("(?) AS e", query).