|
@@ -1009,24 +1009,45 @@ func getCensusIncomeListV2(ch chan models.CensusIncomeChartResp, req fms.IncomeL
|
|
|
|
|
|
//获取最新的开票到款日期
|
|
|
cond := ``
|
|
|
+ historyCond := ``
|
|
|
pars := make([]interface{}, 0)
|
|
|
+ historyPars := make([]interface{}, 0)
|
|
|
|
|
|
if req.SellerIds != "" {
|
|
|
sellerIds := strings.Split(req.SellerIds, ",")
|
|
|
cond += ` AND (a.seller_id in ? )`
|
|
|
- pars = append(pars, sellerIds, sellerIds)
|
|
|
+ historyCond += ` AND (seller_id in ? )`
|
|
|
+ pars = append(pars, sellerIds)
|
|
|
+ historyPars = append(historyPars, sellerIds)
|
|
|
}
|
|
|
if req.CompanyType == 1 {
|
|
|
- cond += ` AND b.new_company = 1 `
|
|
|
+ cond += ` AND b.contract_type = 1 `
|
|
|
+ historyCond += ` AND new_company = 1`
|
|
|
} else if req.CompanyType == 2 {
|
|
|
- cond += ` AND b.new_company = 0 `
|
|
|
+ cond += ` AND b.contract_type = 2 `
|
|
|
+ historyCond += ` AND new_company = 0`
|
|
|
}
|
|
|
+
|
|
|
+ var latestTime time.Time
|
|
|
+
|
|
|
invoiceItem, err := fms.GetLatestIncome(cond, pars)
|
|
|
- if err != nil {
|
|
|
+ if err != nil && err != utils.ErrNoRow {
|
|
|
err = fmt.Errorf("获取最新的开票或到款日期, Err: %s", err.Error())
|
|
|
return
|
|
|
}
|
|
|
- invoiceItem.InvoiceDate = invoiceItem.InvoiceDate.AddDate(0,0,-invoiceItem.InvoiceDate.Day()+1)
|
|
|
+ latestTime = invoiceItem.InvoiceDate
|
|
|
+
|
|
|
+ if err == utils.ErrNoRow{
|
|
|
+ historyItem, e := fms.GetLatestHistoryIncome(historyCond, historyPars)
|
|
|
+ if e != nil {
|
|
|
+ err = fmt.Errorf("获取最新的历史开票或到款日期, Err: %s", err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ latestTime = historyItem.InvoiceDate
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ latestTime = latestTime.AddDate(0,0,-latestTime.Day()+1)
|
|
|
|
|
|
var dateSlice []string
|
|
|
var totalMoneySlice, prevTotalMoneySlice []float64
|
|
@@ -1040,16 +1061,16 @@ func getCensusIncomeListV2(ch chan models.CensusIncomeChartResp, req fms.IncomeL
|
|
|
ed := fmt.Sprint(req.EndDate, "-01 23:59:59")
|
|
|
reqStartDate, _ = time.Parse(utils.FormatDateTime, st)
|
|
|
reqEndDate, _ = time.Parse(utils.FormatDateTime, ed)
|
|
|
- if reqEndDate.After(invoiceItem.InvoiceDate) {
|
|
|
- yearNum = invoiceItem.InvoiceDate.Year() - reqStartDate.Year()
|
|
|
- monthNum = int(invoiceItem.InvoiceDate.Month() - reqStartDate.Month())
|
|
|
+ if reqEndDate.After(latestTime) {
|
|
|
+ yearNum = latestTime.Year() - reqStartDate.Year()
|
|
|
+ monthNum = int(latestTime.Month() - reqStartDate.Month())
|
|
|
} else {
|
|
|
yearNum = reqEndDate.Year() - reqStartDate.Year()
|
|
|
monthNum = int(reqEndDate.Month() - reqStartDate.Month())
|
|
|
}
|
|
|
} else {
|
|
|
- yearNum = invoiceItem.InvoiceDate.Year() - 2020
|
|
|
- monthNum = int(invoiceItem.InvoiceDate.Month() - 1)
|
|
|
+ yearNum = latestTime.Year() - 2020
|
|
|
+ monthNum = int(latestTime.Month() - 1)
|
|
|
}
|
|
|
|
|
|
if yearNum < 0 {
|
|
@@ -1074,7 +1095,7 @@ func getCensusIncomeListV2(ch chan models.CensusIncomeChartResp, req fms.IncomeL
|
|
|
//dataList := make([]*fms.IncomeSummaryItem, 0)
|
|
|
//historydataList := make([]*fms.IncomeSummaryItem, 0)
|
|
|
fmt.Println("numMonth:", numMonth)
|
|
|
- fmt.Println("InvoiceDate:", invoiceItem.InvoiceDate)
|
|
|
+ fmt.Println("InvoiceDate:", latestTime)
|
|
|
|
|
|
var j int
|
|
|
for i := 0; i <= numMonth; i++ {
|
|
@@ -1089,8 +1110,8 @@ func getCensusIncomeListV2(ch chan models.CensusIncomeChartResp, req fms.IncomeL
|
|
|
startDate = reqStartDate.AddDate(0, i, 0).Format("2006-01")
|
|
|
prevStartDate = reqStartDate.AddDate(-1, i, 0).Format("2006-01")
|
|
|
} else {
|
|
|
- startDate = invoiceItem.InvoiceDate.AddDate(0, i-numMonth, 0).Format("2006-01")
|
|
|
- prevStartDate = invoiceItem.InvoiceDate.AddDate(-1, i-numMonth, 0).Format("2006-01")
|
|
|
+ startDate = latestTime.AddDate(0, i-numMonth, 0).Format("2006-01")
|
|
|
+ prevStartDate = latestTime.AddDate(-1, i-numMonth, 0).Format("2006-01")
|
|
|
}
|
|
|
startDate = fmt.Sprint(startDate, "-01")
|
|
|
prevStartDate = fmt.Sprint(prevStartDate, "-01")
|
|
@@ -1101,13 +1122,13 @@ func getCensusIncomeListV2(ch chan models.CensusIncomeChartResp, req fms.IncomeL
|
|
|
if req.StartDate != "" && req.EndDate != "" {
|
|
|
endDateTime = reqStartDate.AddDate(0, i+1, -1)
|
|
|
prevEndDateTime = reqStartDate.AddDate(-1, i+1, -1)
|
|
|
- if reqEndDate.After(invoiceItem.InvoiceDate) {
|
|
|
- endDateTime = invoiceItem.InvoiceDate.AddDate(0, i-numMonth+1, -1)
|
|
|
- prevEndDateTime = invoiceItem.InvoiceDate.AddDate(-1, i-numMonth+1, -1)
|
|
|
+ if reqEndDate.After(latestTime) {
|
|
|
+ endDateTime = latestTime.AddDate(0, i-numMonth+1, -1)
|
|
|
+ prevEndDateTime = latestTime.AddDate(-1, i-numMonth+1, -1)
|
|
|
}
|
|
|
} else {
|
|
|
- endDateTime = invoiceItem.InvoiceDate.AddDate(0, i-numMonth+1, -1)
|
|
|
- prevEndDateTime = invoiceItem.InvoiceDate.AddDate(-1, i-numMonth+1, -1)
|
|
|
+ endDateTime = latestTime.AddDate(0, i-numMonth+1, -1)
|
|
|
+ prevEndDateTime = latestTime.AddDate(-1, i-numMonth+1, -1)
|
|
|
}
|
|
|
endDate = endDateTime.Format(utils.FormatDate)
|
|
|
prevEndDate = prevEndDateTime.Format(utils.FormatDate)
|