|
@@ -15,6 +15,7 @@ import (
|
|
|
fmsService "hongze/fms_api/services/fms"
|
|
|
"hongze/fms_api/utils"
|
|
|
"net/http"
|
|
|
+ "sort"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
"sync"
|
|
@@ -1424,7 +1425,11 @@ func (this *InvoicePaymentController) IncomeList(c *gin.Context) {
|
|
|
incomeList = v
|
|
|
close(ch)
|
|
|
}
|
|
|
-
|
|
|
+ // 是否导出
|
|
|
+ if req.IsExport == 1 {
|
|
|
+ ExportIncomeList(c, incomeList.DataList)
|
|
|
+ return
|
|
|
+ }
|
|
|
resp.OkData("获取成功", incomeList, c)
|
|
|
}
|
|
|
|
|
@@ -1442,71 +1447,105 @@ func getCensusIncomeListV2(ch chan models.CensusIncomeChartResp, req fms.IncomeL
|
|
|
//
|
|
|
//redisJsonData, redisErr := global.Redis.Get(context.TODO(), key).Result()
|
|
|
//if redisErr != nil {
|
|
|
+
|
|
|
+ //获取最新的开票到款日期
|
|
|
+ invoiceItem,err := fms.GetLatestInvoice()
|
|
|
+ if err != nil {
|
|
|
+ err = fmt.Errorf("获取最新的开票或到款日期, Err: %s", err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
var dateSlice []string
|
|
|
- var totalMoneySlice, prevTotalMoneySlice, yoySlice []float64
|
|
|
+ var totalMoneySlice, prevTotalMoneySlice []float64
|
|
|
+ var yoySlice []string
|
|
|
var yearNum, monthNum int
|
|
|
+ var reqStartDate, reqEndDate time.Time
|
|
|
+ historyTime, _ := time.Parse(utils.FormatDate, "2023-03-01")
|
|
|
+
|
|
|
if req.StartDate != "" && req.EndDate != "" {
|
|
|
st := fmt.Sprint(req.StartDate, "-01 00:00:00")
|
|
|
ed := fmt.Sprint(req.EndDate, "-01 23:59:59")
|
|
|
- startDate,_ := time.Parse(st, utils.FormatDateTime)
|
|
|
- endDate,_ := time.Parse(ed, utils.FormatDateTime)
|
|
|
- yearNum = startDate.Year() - endDate.Year()
|
|
|
- monthNum = int(startDate.Month() - endDate.Month())
|
|
|
+ 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() - 1)
|
|
|
+ } else {
|
|
|
+ yearNum = reqEndDate.Year() - reqStartDate.Year()
|
|
|
+ monthNum = int(reqEndDate.Month() - 1)
|
|
|
+ }
|
|
|
} else {
|
|
|
- yearNum = time.Now().Year() - 2020
|
|
|
- monthNum = int(time.Now().Month() - 1)
|
|
|
+ yearNum = invoiceItem.InvoiceDate.Year() - 2020
|
|
|
+ monthNum = int(invoiceItem.InvoiceDate.Month() - 1)
|
|
|
}
|
|
|
|
|
|
numMonth := yearNum*12 + monthNum //共存在多少个月
|
|
|
- if req.ListParam == "1" {
|
|
|
- numMonth = numMonth/3
|
|
|
- } else if req.ListParam == "2" {
|
|
|
- numMonth = numMonth/6
|
|
|
- } else if req.ListParam == "3" {
|
|
|
- numMonth = numMonth/12
|
|
|
- }
|
|
|
+ //if req.ListParam == "1" {
|
|
|
+ // numMonth = numMonth / 3
|
|
|
+ //} else if req.ListParam == "2" {
|
|
|
+ // numMonth = numMonth / 6
|
|
|
+ //} else if req.ListParam == "3" {
|
|
|
+ // numMonth = numMonth / 12
|
|
|
+ //}
|
|
|
// 累计值
|
|
|
var accumulate float64
|
|
|
- for i := numMonth; i >= 0; i-- {
|
|
|
- if req.ListParam == "1" {
|
|
|
- i = i-2
|
|
|
- } else if req.ListParam == "2" {
|
|
|
- i = i-5
|
|
|
- } else if req.ListParam == "3" {
|
|
|
- i = i-11
|
|
|
- }
|
|
|
- timeNow, _ := time.Parse("2006-01", time.Now().Format("2006-01"))
|
|
|
- dateSlice = append(dateSlice, timeNow.AddDate(0, -i, 0).Format("06/01"))
|
|
|
+ var historyAccumulate float64
|
|
|
+ fmt.Println("numMonth:",numMonth)
|
|
|
+
|
|
|
+ for i := 0; i <= numMonth; i++ {
|
|
|
+ //timeNow, _ := time.Parse("2006-01", time.Now().Format("2006-01"))
|
|
|
+
|
|
|
+ var endDateTime time.Time
|
|
|
+ var prevEndDateTime time.Time
|
|
|
+ var prevStartDate, prevEndDate string
|
|
|
+ var startDate, endDate string
|
|
|
//开始日期
|
|
|
- startDate := timeNow.AddDate(0, -i, 0).Format("2006-01")
|
|
|
- prevStartDate := timeNow.AddDate(0, -i-1, 0).Format("2006-01")
|
|
|
+ if req.StartDate != "" && req.EndDate != "" {
|
|
|
+ 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 = fmt.Sprint(startDate, "-01")
|
|
|
prevStartDate = fmt.Sprint(prevStartDate, "-01")
|
|
|
+ startDateTime, _ := time.Parse(utils.FormatDate, startDate)
|
|
|
+ prevStartDateTime, _ := time.Parse(utils.FormatDate, prevStartDate)
|
|
|
|
|
|
//结束日期
|
|
|
- endDateTime := timeNow.AddDate(0, -i+1, -1)
|
|
|
- prevEndDateTime := timeNow.AddDate(0, -i, -1)
|
|
|
- endDate := endDateTime.Format(utils.FormatDate)
|
|
|
- prevEndDate := prevEndDateTime.Format(utils.FormatDate)
|
|
|
-
|
|
|
- //因为就算是当月的后续事件还没到,也要计入数据统计,所以不做限制到当天处理
|
|
|
- //if endDateTime.After(time.Now()) {
|
|
|
- // endDate = time.Now().AddDate(0, 0, 1).Format(utils.FormatDate)
|
|
|
- //} else {
|
|
|
- // endDate = fmt.Sprint(endDate, "-01")
|
|
|
- //}
|
|
|
+ if req.StartDate != "" && req.EndDate != "" {
|
|
|
+ endDateTime = reqStartDate.AddDate(0, i+1, -1)
|
|
|
+ prevEndDateTime = reqStartDate.AddDate(-1, i+1, -1)
|
|
|
+ } else {
|
|
|
+ endDateTime = invoiceItem.InvoiceDate.AddDate(0, i-numMonth+1, -1)
|
|
|
+ prevEndDateTime = invoiceItem.InvoiceDate.AddDate(-1, i-numMonth+1, -1)
|
|
|
+ }
|
|
|
+ endDate = endDateTime.Format(utils.FormatDate)
|
|
|
+ prevEndDate = prevEndDateTime.Format(utils.FormatDate)
|
|
|
+
|
|
|
+
|
|
|
+ dateSlice = append(dateSlice, startDateTime.Format("06/01"))
|
|
|
+
|
|
|
cond := `1 = 1`
|
|
|
+ histrtyCond := `1 = 1`
|
|
|
pars := make([]interface{}, 0)
|
|
|
+ historyPars := make([]interface{}, 0)
|
|
|
|
|
|
prevCond := `1 = 1`
|
|
|
+ prevHistoryCond := `1 = 1`
|
|
|
prevPars := make([]interface{}, 0)
|
|
|
+ prevHistoryPars := make([]interface{}, 0)
|
|
|
|
|
|
if req.CompanyType == 1 {
|
|
|
cond += ` AND b.new_company = 1 `
|
|
|
prevCond += ` AND b.new_company = 1 `
|
|
|
+ histrtyCond += ` AND new_company = 1 `
|
|
|
+ prevHistoryCond += ` AND new_company = 1 `
|
|
|
} else if req.CompanyType == 2 {
|
|
|
cond += ` AND b.new_company = 0 `
|
|
|
prevCond += ` AND b.new_company = 0 `
|
|
|
+ histrtyCond += ` AND new_company = 0 `
|
|
|
+ prevHistoryCond += ` AND new_company = 0 `
|
|
|
}
|
|
|
|
|
|
if req.SellerIds != "" {
|
|
@@ -1515,84 +1554,278 @@ func getCensusIncomeListV2(ch chan models.CensusIncomeChartResp, req fms.IncomeL
|
|
|
pars = append(pars, sellerIds, sellerIds)
|
|
|
prevCond += ` AND (c.seller_id in ? OR d.seller_id in ?)`
|
|
|
prevPars = append(prevPars, sellerIds, sellerIds)
|
|
|
+ histrtyCond += ` AND seller_id in ? `
|
|
|
+ prevHistoryCond += ` AND seller_id in ? `
|
|
|
+ historyPars = append(historyPars, sellerIds)
|
|
|
+ prevHistoryPars = append(prevHistoryPars, sellerIds)
|
|
|
}
|
|
|
|
|
|
{
|
|
|
+ //本期
|
|
|
st := fmt.Sprint(startDate, " 00:00:00")
|
|
|
ed := fmt.Sprint(endDate, " 23:59:59")
|
|
|
- cond += ` AND ((c.invoice_time BETWEEN ? AND ?) or (d.invoice_time BETWEEN ? AND ?))`
|
|
|
- pars = append(pars, st, ed, st, ed)
|
|
|
- summaryIds, e := fms.GetInvoicePaymentCensusSummaryDataIds(cond, pars)
|
|
|
- if e != nil {
|
|
|
- return
|
|
|
- }
|
|
|
+ //校验日期,分段查询
|
|
|
+ if startDateTime.After(historyTime) || startDateTime.Equal(historyTime) {
|
|
|
+ //全部走新查询
|
|
|
+ //fmt.Println("新查询")
|
|
|
+ cond += ` AND ((c.invoice_time BETWEEN ? AND ?) or (d.invoice_time BETWEEN ? AND ?))`
|
|
|
+ pars = append(pars, st, ed, st, ed)
|
|
|
+ summaryIds, e := fms.GetInvoicePaymentCensusSummaryDataIds(cond, pars)
|
|
|
+ if e != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
|
|
|
- // 开票到款金额合计(换算后)
|
|
|
- var amountTotal float64
|
|
|
+ // 开票到款金额合计(换算后)
|
|
|
+ var amountTotal float64
|
|
|
+
|
|
|
+ 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)
|
|
|
+ amountCond += ` AND (b.invoice_time BETWEEN ? AND ?)`
|
|
|
+ amountPars = append(amountPars, st, ed)
|
|
|
+ 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)
|
|
|
+ }
|
|
|
+ } else if endDateTime.Before(historyTime) || endDateTime.Equal(historyTime) {
|
|
|
+
|
|
|
+ //全部走旧查询
|
|
|
+ //fmt.Println("旧查询")
|
|
|
+ histrtyCond += ` AND (invoice_time BETWEEN ? AND ? )`
|
|
|
+ historyPars = append(historyPars, st, ed)
|
|
|
+ // 开票到款金额合计(换算后)
|
|
|
+ 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
|
|
|
|
|
|
- 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)
|
|
|
- amountSum, e := fms.GetContractSummaryInvoicePaymentAmount(amountCond, amountPars)
|
|
|
+ if req.ListParam == "4" {
|
|
|
+ totalMoneySlice = append(totalMoneySlice, accumulate)
|
|
|
+ } else {
|
|
|
+ totalMoneySlice = append(totalMoneySlice, amountTotal)
|
|
|
+ }
|
|
|
+ } 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())
|
|
|
+ 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)
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
- if req.ListParam == "4"{
|
|
|
- totalMoneySlice = append(totalMoneySlice, accumulate)
|
|
|
- }else {
|
|
|
- totalMoneySlice = append(totalMoneySlice, amountTotal)
|
|
|
- }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
{ //去年同期,用于计算同比值
|
|
|
-
|
|
|
prevSt := fmt.Sprint(prevStartDate, " 00:00:00")
|
|
|
prevEd := fmt.Sprint(prevEndDate, " 23:59:59")
|
|
|
- prevCond += ` AND ((c.invoice_time BETWEEN ? AND ?) or (d.invoice_time BETWEEN ? AND ?))`
|
|
|
- prevPars = append(prevPars, prevSt, prevEd, prevSt, prevEd)
|
|
|
- prevSummaryIds, e := fms.GetInvoicePaymentCensusSummaryDataIds(prevCond, prevPars)
|
|
|
- if e != nil {
|
|
|
- return
|
|
|
- }
|
|
|
|
|
|
- // 开票到款金额合计(换算后)
|
|
|
- var prevAmountTotal float64
|
|
|
+ //校验日期,分段查询
|
|
|
+ if prevStartDateTime.After(historyTime) || prevStartDateTime.Equal(historyTime) {
|
|
|
+ //全部走新查询
|
|
|
+ prevCond += ` AND ((c.invoice_time BETWEEN ? AND ?) or (d.invoice_time BETWEEN ? AND ?))`
|
|
|
+ prevPars = append(prevPars, prevSt, prevEd, prevSt, 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)
|
|
|
+ amountCond += ` AND (b.invoice_time BETWEEN ? AND ?)`
|
|
|
+ amountPars = append(amountPars, prevSt, prevEd)
|
|
|
+ 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
|
|
|
+ }
|
|
|
+ prevTotalMoneySlice = append(prevTotalMoneySlice, prevAmountTotal)
|
|
|
+ } else if prevEndDateTime.Before(historyTime) || prevEndDateTime.Equal(historyTime) {
|
|
|
+ //全部走旧查询
|
|
|
+ prevHistoryCond += ` AND (invoice_time BETWEEN ? AND ?)`
|
|
|
+ prevHistoryPars = append(prevHistoryPars, prevSt, prevEd)
|
|
|
+ // 开票到款金额合计(换算后)
|
|
|
+ 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
|
|
|
+
|
|
|
+ if req.ListParam == "4" {
|
|
|
+ prevTotalMoneySlice = append(prevTotalMoneySlice, historyAccumulate)
|
|
|
+ } else {
|
|
|
+ prevTotalMoneySlice = append(prevTotalMoneySlice, amountTotal)
|
|
|
+ }
|
|
|
+ } 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
|
|
|
+
|
|
|
|
|
|
- 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)
|
|
|
- amountSum, e := fms.GetContractSummaryInvoicePaymentAmount(amountCond, amountPars)
|
|
|
+ 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 {
|
|
|
- err = fmt.Errorf("获取汇总金额合计失败, Err: %s", e.Error())
|
|
|
return
|
|
|
}
|
|
|
- prevAmountTotal, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", amountSum), 64)
|
|
|
+
|
|
|
+ // 开票到款金额合计(换算后)
|
|
|
+ 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)
|
|
|
+ }
|
|
|
}
|
|
|
- prevTotalMoneySlice = append(prevTotalMoneySlice, prevAmountTotal)
|
|
|
+
|
|
|
+ }
|
|
|
+ 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))
|
|
|
|
|
|
//计算同比值
|
|
|
for i := range prevTotalMoneySlice {
|
|
|
var yoy float64
|
|
|
- fmt.Println("1:", prevTotalMoneySlice[i])
|
|
|
- fmt.Println("2:", totalMoneySlice[i])
|
|
|
- fmt.Println("3:", totalMoneySlice[i]-prevTotalMoneySlice[i])
|
|
|
- if prevTotalMoneySlice[i] != 0 {
|
|
|
+ var yoyStr string
|
|
|
+ //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)
|
|
|
}
|
|
|
- yoySlice = append(yoySlice, yoy)
|
|
|
+ yoySlice = append(yoySlice, yoyStr)
|
|
|
}
|
|
|
|
|
|
incomeChart.Title = "开票到款统计图"
|
|
|
incomeChart.Date = dateSlice
|
|
|
incomeChart.TotalMoney = totalMoneySlice
|
|
|
+ incomeChart.PrevTotalMoney = prevTotalMoneySlice
|
|
|
incomeChart.Yoy = yoySlice
|
|
|
|
|
|
//redisJsonData, err := json.Marshal(incomeChart)
|
|
@@ -1608,3 +1841,57 @@ func getCensusIncomeListV2(ch chan models.CensusIncomeChartResp, req fms.IncomeL
|
|
|
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+// ExportIncomeList 导出业务收入统计列表
|
|
|
+func ExportIncomeList(c *gin.Context, list []*fms.IncomeSummaryItem) {
|
|
|
+ // 生成Excel文件
|
|
|
+ xlsxFile := xlsx.NewFile()
|
|
|
+ style := xlsx.NewStyle()
|
|
|
+ alignment := xlsx.Alignment{
|
|
|
+ Horizontal: "center",
|
|
|
+ Vertical: "center",
|
|
|
+ WrapText: true,
|
|
|
+ }
|
|
|
+ style.Alignment = alignment
|
|
|
+ style.ApplyAlignment = true
|
|
|
+
|
|
|
+ sheetName := "业务收入统计表"
|
|
|
+ sheet, err := xlsxFile.AddSheet(sheetName)
|
|
|
+ if err != nil {
|
|
|
+ resp.FailData("新增Sheet失败", "Err:"+err.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 数据表头
|
|
|
+ rowTitle := []string{"开票日期", "新客户(1)", "客户名称", "金额", "销售"}
|
|
|
+ titleRow := sheet.AddRow()
|
|
|
+ for i := range rowTitle {
|
|
|
+ v := titleRow.AddCell()
|
|
|
+ v.SetString(rowTitle[i])
|
|
|
+ v.SetStyle(style)
|
|
|
+ }
|
|
|
+ incomeSummaryItemList := make(fms.IncomeSummaryItemList, 0)
|
|
|
+ incomeSummaryItemList = list
|
|
|
+ sort.Sort(incomeSummaryItemList)
|
|
|
+ // 填充数据
|
|
|
+ for _, v := range incomeSummaryItemList {
|
|
|
+ dataRow := sheet.AddRow()
|
|
|
+ dataRow.AddCell().SetString(v.InvoiceDate.Format(utils.FormatDate)) // 开票日期
|
|
|
+ dataRow.AddCell().SetString(strconv.Itoa(v.NewCompany)) // 新客户
|
|
|
+ dataRow.AddCell().SetString(v.CompanyName) // 客户名称
|
|
|
+ dataRow.AddCell().SetString(fmt.Sprint(v.Amount)) // 金额
|
|
|
+ dataRow.AddCell().SetString(v.SellerName) // 销售员
|
|
|
+ }
|
|
|
+
|
|
|
+ // 输出文件
|
|
|
+ var buffer bytes.Buffer
|
|
|
+ _ = xlsxFile.Write(&buffer)
|
|
|
+ content := bytes.NewReader(buffer.Bytes())
|
|
|
+ randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
|
|
|
+ fileName := sheetName + randStr + ".xlsx"
|
|
|
+
|
|
|
+ c.Writer.Header().Add("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"`, fileName))
|
|
|
+ c.Writer.Header().Add("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
|
|
|
+ http.ServeContent(c.Writer, c.Request, fileName, time.Now(), content)
|
|
|
+}
|
|
|
+
|