ziwen 1 rok pred
rodič
commit
b9ed9743cd

+ 68 - 15
controller/census/invoice_payment.go

@@ -1004,7 +1004,20 @@ func getCensusIncomeListV2(ch chan models.CensusIncomeChartResp, req fms.IncomeL
 	//if redisErr != nil {
 
 	//获取最新的开票到款日期
-	invoiceItem, err := fms.GetLatestIncome()
+	cond := ``
+	pars := make([]interface{}, 0)
+
+	if req.SellerIds != "" {
+		sellerIds := strings.Split(req.SellerIds, ",")
+		cond += ` AND (a.seller_id in ? )`
+		pars = append(pars, sellerIds, sellerIds)
+	}
+	if req.CompanyType == 1 {
+		cond += ` AND b.new_company = 1 `
+	} else if req.CompanyType == 2 {
+		cond += ` AND b.new_company = 0 `
+	}
+	invoiceItem, err := fms.GetLatestIncome(cond, pars)
 	if err != nil {
 		err = fmt.Errorf("获取最新的开票或到款日期, Err: %s", err.Error())
 		return
@@ -1045,7 +1058,9 @@ func getCensusIncomeListV2(ch chan models.CensusIncomeChartResp, req fms.IncomeL
 	//}
 	// 累计值
 	var accumulate float64
+	var partAccumulate float64
 	var historyAccumulate float64
+	var partHistoryAccumulate float64
 	//dataList := make([]*fms.IncomeSummaryItem, 0)
 	//historydataList := make([]*fms.IncomeSummaryItem, 0)
 	fmt.Println("numMonth:", numMonth)
@@ -1120,7 +1135,8 @@ func getCensusIncomeListV2(ch chan models.CensusIncomeChartResp, req fms.IncomeL
 			historyPars = append(historyPars, sellerIds)
 			prevHistoryPars = append(prevHistoryPars, sellerIds)
 		}
-
+//fmt.Println("i:",i)
+//fmt.Println("j:",j)
 		{
 			//本期
 			st := fmt.Sprint(startDate, " 00:00:00")
@@ -1158,12 +1174,16 @@ func getCensusIncomeListV2(ch chan models.CensusIncomeChartResp, req fms.IncomeL
 					}
 					amountTotal, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", amountSum), 64)
 					accumulate += amountTotal
+					partAccumulate += amountTotal
 				}
 				if i == j {
 					if req.ListParam == "4" {
 						totalMoneySlice = append(totalMoneySlice, accumulate)
-					} else {
+					} else if req.ListParam == "0" {
 						totalMoneySlice = append(totalMoneySlice, amountTotal)
+					} else if i > 0 {
+						totalMoneySlice = append(totalMoneySlice, partAccumulate)
+						partAccumulate  = 0.0
 					}
 				}
 			} else if endDateTime.Before(historyTime) || endDateTime.Equal(historyTime) {
@@ -1171,6 +1191,8 @@ func getCensusIncomeListV2(ch chan models.CensusIncomeChartResp, req fms.IncomeL
 				//fmt.Println("旧查询")
 				histrtyCond += ` AND (invoice_time BETWEEN ? AND ? )`
 				historyPars = append(historyPars, st, ed)
+				//fmt.Println("st:",st)
+				//fmt.Println("ed:",ed)
 				// 开票到款金额合计(换算后)
 				var amountTotal float64
 				results, e := fms.GetIncomeHistory(histrtyCond, historyPars)
@@ -1186,14 +1208,20 @@ func getCensusIncomeListV2(ch chan models.CensusIncomeChartResp, req fms.IncomeL
 				}
 				amountTotal, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", amountSum), 64)
 				accumulate += amountTotal
+				partAccumulate += amountTotal
 
 				if i == j {
 					if req.ListParam == "4" {
 						totalMoneySlice = append(totalMoneySlice, accumulate)
-					} else {
+					} else if req.ListParam == "0" {
 						totalMoneySlice = append(totalMoneySlice, amountTotal)
+					} else if i > 0 {
+						totalMoneySlice = append(totalMoneySlice, partAccumulate)
+						partAccumulate  = 0.0
 					}
 				}
+
+				fmt.Println("partAccumulate:",partAccumulate)
 			}
 			//else {
 			//	//刚好跨过20230301的,各查一部分
@@ -1282,17 +1310,21 @@ func getCensusIncomeListV2(ch chan models.CensusIncomeChartResp, req fms.IncomeL
 					var amountSum float64
 					//historydataList = append(historydataList, results...)
 					for _, result := range results {
-
 						amountSum += result.Amount
 					}
 					prevAmountTotal, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", amountSum), 64)
 					historyAccumulate += prevAmountTotal
+					partHistoryAccumulate += prevAmountTotal
 				}
 				if i == j {
 					if req.ListParam == "4" {
 						prevTotalMoneySlice = append(prevTotalMoneySlice, historyAccumulate)
-					} else {
-						prevTotalMoneySlice = append(prevTotalMoneySlice, prevAmountTotal)
+					} else if req.ListParam == "0" {
+						prevTotalMoneySlice = append(prevTotalMoneySlice, partHistoryAccumulate)
+						partHistoryAccumulate = 0.0
+					} else if i > 0 {
+						prevTotalMoneySlice = append(prevTotalMoneySlice, partHistoryAccumulate)
+						partHistoryAccumulate  = 0.0
 					}
 				}
 			} else if prevEndDateTime.Before(historyTime) || prevEndDateTime.Equal(historyTime) {
@@ -1313,12 +1345,17 @@ func getCensusIncomeListV2(ch chan models.CensusIncomeChartResp, req fms.IncomeL
 				}
 				amountTotal, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", amountSum), 64)
 				historyAccumulate += amountTotal
+				partHistoryAccumulate += amountTotal
 
 				if i == j {
 					if req.ListParam == "4" {
 						prevTotalMoneySlice = append(prevTotalMoneySlice, historyAccumulate)
-					} else {
-						prevTotalMoneySlice = append(prevTotalMoneySlice, amountTotal)
+					} else if req.ListParam == "0" {
+						prevTotalMoneySlice = append(prevTotalMoneySlice, partHistoryAccumulate)
+						partHistoryAccumulate = 0.0
+					} else if i > 0 {
+						prevTotalMoneySlice = append(prevTotalMoneySlice, partHistoryAccumulate)
+						partHistoryAccumulate  = 0.0
 					}
 				}
 			}
@@ -1375,14 +1412,30 @@ func getCensusIncomeListV2(ch chan models.CensusIncomeChartResp, req fms.IncomeL
 			//	}
 			//}
 			if req.ListParam == "1" && i == j {
-				dateSlice = append(dateSlice, startDateTime.AddDate(0, 2, 0).Format("06/01"))
-				j = j + 2
+				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 {
-				j = j + 5
-				dateSlice = append(dateSlice, startDateTime.AddDate(0, 5, 0).Format("06/01"))
+				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 {
-				j = j + 11
-				dateSlice = append(dateSlice, startDateTime.AddDate(0, 11, 0).Format("06/01"))
+				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++

+ 11 - 4
models/fms/contract_invoice.go

@@ -650,9 +650,16 @@ type IncomeListReq struct {
 }
 
 //获取最新的开票或到款日期
-func GetLatestIncome() (result *ContractInvoice, err error) {
-	sql := `SELECT * FROM contract_invoice WHERE is_deleted = 0  ORDER BY invoice_time DESC  `
-
-	err = global.DEFAULT_MYSQL.Raw(sql).First(&result).Error
+func GetLatestIncome(condition string, pars []interface{}) (result *ContractInvoice, err error) {
+	sql := `SELECT
+	a.* 
+FROM
+	contract_invoice AS a
+	INNER JOIN contract_register AS b ON a.contract_register_id = b.contract_register_id 
+WHERE
+	a.is_deleted = 0 `
+	sql += condition
+	sql += `ORDER BY a.invoice_time DESC  `
+	err = global.DEFAULT_MYSQL.Raw(sql, pars...).First(&result).Error
 	return
 }