|
@@ -10,7 +10,6 @@ import (
|
|
|
"hongze/fms_api/global"
|
|
|
"hongze/fms_api/models/base"
|
|
|
"hongze/fms_api/models/fms"
|
|
|
- fmsService "hongze/fms_api/services/fms"
|
|
|
"hongze/fms_api/utils"
|
|
|
"net/http"
|
|
|
"strconv"
|
|
@@ -23,256 +22,256 @@ import (
|
|
|
type InvoicePaymentController struct{}
|
|
|
|
|
|
// List2 原版(已废弃)
|
|
|
-func (ct *InvoicePaymentController) List2(c *gin.Context) {
|
|
|
- var req fms.InvoicePaymentCensusListReq
|
|
|
- if e := c.BindQuery(&req); e != nil {
|
|
|
- err, ok := e.(validator.ValidationErrors)
|
|
|
- if !ok {
|
|
|
- resp.FailData("参数解析失败", "Err:"+e.Error(), c)
|
|
|
- return
|
|
|
- }
|
|
|
- resp.FailData("参数解析失败", err.Translate(global.Trans), c)
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- cond := `1 = 1`
|
|
|
- pars := make([]interface{}, 0)
|
|
|
- // 合同编号/客户姓名/销售
|
|
|
- if req.Keyword != "" {
|
|
|
- kw := "%" + req.Keyword + "%"
|
|
|
- cond += ` AND b.company_name LIKE ? OR a.seller_name LIKE ?`
|
|
|
- pars = append(pars, kw, kw)
|
|
|
- }
|
|
|
- if req.SellGroupId > 0 {
|
|
|
- cond += ` AND a.seller_group_id = ?`
|
|
|
- pars = append(pars, req.SellGroupId)
|
|
|
- }
|
|
|
- // 套餐筛选
|
|
|
- if req.ServiceType != 0 {
|
|
|
- registerIds, e := fms.GetContractRegisterIdsByTempId(req.ServiceType)
|
|
|
- if e != nil {
|
|
|
- resp.FailMsg("获取失败", "获取合同登记IDs失败, Err: "+e.Error(), c)
|
|
|
- return
|
|
|
- }
|
|
|
- if len(registerIds) > 0 {
|
|
|
- cond += ` AND b.contract_register_id IN ?`
|
|
|
- pars = append(pars, registerIds)
|
|
|
- } else {
|
|
|
- cond += ` AND 1 = 2`
|
|
|
- }
|
|
|
- }
|
|
|
- // 开票到款日期
|
|
|
- if req.TimeType > 0 && req.StartDate != "" && req.EndDate != "" {
|
|
|
- st := fmt.Sprint(req.StartDate, " 00:00:00")
|
|
|
- ed := fmt.Sprint(req.EndDate, " 23:59:59")
|
|
|
- cond += ` AND a.invoice_type = ? AND (a.invoice_time BETWEEN ? AND ?)`
|
|
|
- pars = append(pars, req.TimeType, st, ed)
|
|
|
- }
|
|
|
- // 已开票
|
|
|
- if req.HasInvoice == 1 && req.HasPayment == 0 {
|
|
|
- cond += ` AND a.invoice_type = 1`
|
|
|
- }
|
|
|
- // 已到款
|
|
|
- if req.HasInvoice == 0 && req.HasPayment == 1 {
|
|
|
- cond += ` AND a.invoice_type = 2`
|
|
|
- }
|
|
|
-
|
|
|
- page := new(base.Page)
|
|
|
- page.SetPageSize(req.PageSize)
|
|
|
- page.SetCurrent(req.Current)
|
|
|
- page.AddOrderItem(base.OrderItem{Column: "a.create_time", Asc: false})
|
|
|
- page.AddOrderItem(base.OrderItem{Column: "b.contract_register_id", Asc: true})
|
|
|
- if req.IsExport == 1 {
|
|
|
- page.SetPageSize(10000)
|
|
|
- page.SetCurrent(1)
|
|
|
- }
|
|
|
-
|
|
|
- list, allRegisterIds, e := fms.GetInvoicePaymentCensusPageList(page, cond, pars)
|
|
|
- if e != nil {
|
|
|
- resp.FailMsg("获取失败", "获取商品到款统计列表失败, Err: "+e.Error(), c)
|
|
|
- return
|
|
|
- }
|
|
|
- total := int64(len(allRegisterIds))
|
|
|
- registerIds := make([]int, 0)
|
|
|
- for i := range list {
|
|
|
- registerIds = append(registerIds, list[i].ContractRegisterId)
|
|
|
- }
|
|
|
-
|
|
|
- results := new(fms.InvoicePaymentCensusResp)
|
|
|
- if len(registerIds) > 0 {
|
|
|
- // 获取开票到款列表
|
|
|
- ivCond := `contract_register_id IN ?`
|
|
|
- ivPars := make([]interface{}, 0)
|
|
|
- ivPars = append(ivPars, registerIds)
|
|
|
- iv := new(fms.ContractInvoice)
|
|
|
- invoiceList, e := iv.List(ivCond, ivPars, "")
|
|
|
- if e != nil {
|
|
|
- resp.FailMsg("获取失败", "获取开票到款列表失败, Err: "+e.Error(), c)
|
|
|
- return
|
|
|
- }
|
|
|
- // 取出开票、到款
|
|
|
- invoiceMap := make(map[int][]*fms.ContractInvoice, 0)
|
|
|
- paymentMap := make(map[int][]*fms.ContractInvoice, 0)
|
|
|
- paymentIds := make([]int, 0)
|
|
|
- for i := range invoiceList {
|
|
|
- if invoiceMap[invoiceList[i].ContractRegisterId] == nil {
|
|
|
- invoiceMap[invoiceList[i].ContractRegisterId] = make([]*fms.ContractInvoice, 0)
|
|
|
- }
|
|
|
- if paymentMap[invoiceList[i].ContractRegisterId] == nil {
|
|
|
- paymentMap[invoiceList[i].ContractRegisterId] = make([]*fms.ContractInvoice, 0)
|
|
|
- }
|
|
|
- if invoiceList[i].InvoiceType == fms.ContractInvoiceTypeMake {
|
|
|
- invoiceMap[invoiceList[i].ContractRegisterId] = append(invoiceMap[invoiceList[i].ContractRegisterId], invoiceList[i])
|
|
|
- }
|
|
|
- if invoiceList[i].InvoiceType == fms.ContractInvoiceTypePay {
|
|
|
- paymentMap[invoiceList[i].ContractRegisterId] = append(paymentMap[invoiceList[i].ContractRegisterId], invoiceList[i])
|
|
|
- paymentIds = append(paymentIds, invoiceList[i].ContractInvoiceId)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 合同套餐
|
|
|
- contractServiceCond := `contract_register_id IN ?`
|
|
|
- contractServicePars := make([]interface{}, 0)
|
|
|
- contractServicePars = append(contractServicePars, registerIds)
|
|
|
- contractServiceOB := new(fms.ContractService)
|
|
|
- contractServiceList, e := contractServiceOB.List(contractServiceCond, contractServicePars)
|
|
|
- if e != nil {
|
|
|
- resp.FailMsg("获取失败", "获取合同套餐列表失败, Err:"+e.Error(), c)
|
|
|
- return
|
|
|
- }
|
|
|
- contractServiceMap := make(map[int][]*fms.ContractService, 0)
|
|
|
- servicesNameMap := make(map[int][]string, 0)
|
|
|
- for i := range contractServiceList {
|
|
|
- if contractServiceMap[contractServiceList[i].ContractRegisterId] == nil {
|
|
|
- contractServiceMap[contractServiceList[i].ContractRegisterId] = make([]*fms.ContractService, 0)
|
|
|
- }
|
|
|
- contractServiceMap[contractServiceList[i].ContractRegisterId] = append(contractServiceMap[contractServiceList[i].ContractRegisterId], contractServiceList[i])
|
|
|
- servicesNameMap[contractServiceList[i].ContractRegisterId] = append(servicesNameMap[contractServiceList[i].ContractRegisterId], contractServiceList[i].Title)
|
|
|
- }
|
|
|
-
|
|
|
- // 到款套餐分配
|
|
|
- serviceAmountMap := make(map[int][]*fms.ContractPaymentServiceAmount, 0)
|
|
|
- if len(paymentIds) > 0 {
|
|
|
- serviceAmountCond := `contract_payment_id IN ?`
|
|
|
- serviceAmountPars := make([]interface{}, 0)
|
|
|
- serviceAmountPars = append(serviceAmountPars, paymentIds)
|
|
|
- serviceAmountOB := new(fms.ContractPaymentServiceAmount)
|
|
|
- serviceAmountList, e := serviceAmountOB.List(serviceAmountCond, serviceAmountPars)
|
|
|
- if e != nil {
|
|
|
- resp.FailMsg("获取失败", "获取到款套餐分配列表失败, Err:"+e.Error(), c)
|
|
|
- return
|
|
|
- }
|
|
|
- for i := range serviceAmountList {
|
|
|
- if serviceAmountMap[serviceAmountList[i].ContractRegisterId] == nil {
|
|
|
- serviceAmountMap[serviceAmountList[i].ContractRegisterId] = make([]*fms.ContractPaymentServiceAmount, 0)
|
|
|
- }
|
|
|
- serviceAmountMap[serviceAmountList[i].ContractRegisterId] = append(serviceAmountMap[serviceAmountList[i].ContractRegisterId], serviceAmountList[i])
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 整合响应数据
|
|
|
- respList := make([]*fms.InvoicePaymentCensusItem, 0)
|
|
|
- for i := range list {
|
|
|
- v := new(fms.InvoicePaymentCensusItem)
|
|
|
- v.ContractRegisterId = list[i].ContractRegisterId
|
|
|
- v.CompanyName = list[i].CompanyName
|
|
|
- v.NewCompany = list[i].NewCompany
|
|
|
- v.StartDate = list[i].StartDate.Format(utils.FormatDate)
|
|
|
- v.EndDate = list[i].EndDate.Format(utils.FormatDate)
|
|
|
- svList := servicesNameMap[list[i].ContractRegisterId]
|
|
|
- v.ServicesName = strings.Join(svList, ",")
|
|
|
- // 格式化(合并)开票到款数据
|
|
|
- v.InvoicePaymentList = fmsService.MergeInvoiceList2InvoicePaymentCensusInfo(invoiceMap[list[i].ContractRegisterId], paymentMap[list[i].ContractRegisterId],
|
|
|
- contractServiceMap[list[i].ContractRegisterId], serviceAmountMap[list[i].ContractRegisterId])
|
|
|
- respList = append(respList, v)
|
|
|
- }
|
|
|
-
|
|
|
- // 开票到款金额合计(换算后)
|
|
|
- amountTotalCond := `contract_register_id IN ?`
|
|
|
- amountTotalPars := make([]interface{}, 0)
|
|
|
- amountTotalPars = append(amountTotalPars, allRegisterIds)
|
|
|
- amountTotalList, e := fms.GetContractInvoiceAmountTotal(amountTotalCond, amountTotalPars)
|
|
|
- if e != nil {
|
|
|
- resp.FailMsg("获取失败", "获取开票到款金额合计失败, Err:"+e.Error(), c)
|
|
|
- return
|
|
|
- }
|
|
|
- amountTotalMap := make(map[int]float64)
|
|
|
- for i := range amountTotalList {
|
|
|
- amountTotalMap[amountTotalList[i].InvoiceType] = amountTotalList[i].TotalAmount
|
|
|
- }
|
|
|
- invoiceTotal, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", amountTotalMap[fms.ContractInvoiceTypeMake]), 64)
|
|
|
- paymentTotal, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", amountTotalMap[fms.ContractInvoiceTypePay]), 64)
|
|
|
-
|
|
|
- // 分币种金额统计
|
|
|
- currencyOB := new(fms.CurrencyUnit)
|
|
|
- currencyCond := `enable = 1`
|
|
|
- currencyPars := make([]interface{}, 0)
|
|
|
- currencyList, e := currencyOB.List(currencyCond, currencyPars)
|
|
|
- if e != nil {
|
|
|
- resp.FailMsg("获取失败", "获取货币列表失败, Err: "+e.Error(), c)
|
|
|
- return
|
|
|
- }
|
|
|
- unitMap := make(map[string]string)
|
|
|
- invoiceCurrencyTotals := make([]*fms.InvoiceListCurrencyTotal, 0)
|
|
|
- paymentCurrencyTotals := make([]*fms.InvoiceListCurrencyTotal, 0)
|
|
|
- for i := range currencyList {
|
|
|
- unitMap[currencyList[i].Code] = currencyList[i].UnitName
|
|
|
- invoiceCurrencyTotals = append(invoiceCurrencyTotals, &fms.InvoiceListCurrencyTotal{
|
|
|
- Name: currencyList[i].Name,
|
|
|
- UnitName: currencyList[i].UnitName,
|
|
|
- Code: currencyList[i].Code,
|
|
|
- FlagImg: currencyList[i].FlagImg,
|
|
|
- })
|
|
|
- paymentCurrencyTotals = append(paymentCurrencyTotals, &fms.InvoiceListCurrencyTotal{
|
|
|
- Name: currencyList[i].Name,
|
|
|
- UnitName: currencyList[i].UnitName,
|
|
|
- Code: currencyList[i].Code,
|
|
|
- FlagImg: currencyList[i].FlagImg,
|
|
|
- })
|
|
|
- }
|
|
|
- sumList, e := fms.GetInvoiceListCurrencySum(amountTotalCond, amountTotalPars, "currency_unit, invoice_type")
|
|
|
- if e != nil {
|
|
|
- resp.FailMsg("获取失败", "获取商品到款统计货币合计金额失败, Err: "+e.Error(), c)
|
|
|
- return
|
|
|
- }
|
|
|
- invoiceSumMap := make(map[string]float64)
|
|
|
- paymentSumMap := make(map[string]float64)
|
|
|
- for i := range sumList {
|
|
|
- if sumList[i].InvoiceType == fms.ContractInvoiceTypeMake {
|
|
|
- invoiceSumMap[sumList[i].CurrencyUnit] = sumList[i].OriginAmountTotal
|
|
|
- continue
|
|
|
- }
|
|
|
- if sumList[i].InvoiceType == fms.ContractInvoiceTypePay {
|
|
|
- paymentSumMap[sumList[i].CurrencyUnit] = sumList[i].OriginAmountTotal
|
|
|
- }
|
|
|
- }
|
|
|
- for i := range invoiceCurrencyTotals {
|
|
|
- a, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", invoiceSumMap[invoiceCurrencyTotals[i].Code]), 64)
|
|
|
- invoiceCurrencyTotals[i].Amount = a
|
|
|
- }
|
|
|
- for i := range paymentCurrencyTotals {
|
|
|
- a, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", paymentSumMap[paymentCurrencyTotals[i].Code]), 64)
|
|
|
- paymentCurrencyTotals[i].Amount = a
|
|
|
- }
|
|
|
-
|
|
|
- results.DataList = respList
|
|
|
- results.InvoiceTotal = invoiceTotal
|
|
|
- results.PaymentTotal = paymentTotal
|
|
|
- results.InvoiceCurrencyTotal = invoiceCurrencyTotals
|
|
|
- results.PaymentCurrencyTotal = paymentCurrencyTotals
|
|
|
- }
|
|
|
-
|
|
|
- // 是否导出
|
|
|
- if req.IsExport == 1 {
|
|
|
- ExportInvoicePaymentCensusList(c, results)
|
|
|
- return
|
|
|
- }
|
|
|
- page.SetTotal(total)
|
|
|
- baseData := new(base.BaseData)
|
|
|
- baseData.SetPage(page)
|
|
|
- baseData.SetList(results)
|
|
|
- resp.OkData("获取成功", baseData, c)
|
|
|
-}
|
|
|
+//func (ct *InvoicePaymentController) List2(c *gin.Context) {
|
|
|
+// var req fms.InvoicePaymentCensusListReq
|
|
|
+// if e := c.BindQuery(&req); e != nil {
|
|
|
+// err, ok := e.(validator.ValidationErrors)
|
|
|
+// if !ok {
|
|
|
+// resp.FailData("参数解析失败", "Err:"+e.Error(), c)
|
|
|
+// return
|
|
|
+// }
|
|
|
+// resp.FailData("参数解析失败", err.Translate(global.Trans), c)
|
|
|
+// return
|
|
|
+// }
|
|
|
+//
|
|
|
+// cond := `1 = 1`
|
|
|
+// pars := make([]interface{}, 0)
|
|
|
+// // 合同编号/客户姓名/销售
|
|
|
+// if req.Keyword != "" {
|
|
|
+// kw := "%" + req.Keyword + "%"
|
|
|
+// cond += ` AND b.company_name LIKE ? OR a.seller_name LIKE ?`
|
|
|
+// pars = append(pars, kw, kw)
|
|
|
+// }
|
|
|
+// if req.SellGroupId > 0 {
|
|
|
+// cond += ` AND a.seller_group_id = ?`
|
|
|
+// pars = append(pars, req.SellGroupId)
|
|
|
+// }
|
|
|
+// // 套餐筛选
|
|
|
+// if req.ServiceType != 0 {
|
|
|
+// registerIds, e := fms.GetContractRegisterIdsByTempId(req.ServiceType)
|
|
|
+// if e != nil {
|
|
|
+// resp.FailMsg("获取失败", "获取合同登记IDs失败, Err: "+e.Error(), c)
|
|
|
+// return
|
|
|
+// }
|
|
|
+// if len(registerIds) > 0 {
|
|
|
+// cond += ` AND b.contract_register_id IN ?`
|
|
|
+// pars = append(pars, registerIds)
|
|
|
+// } else {
|
|
|
+// cond += ` AND 1 = 2`
|
|
|
+// }
|
|
|
+// }
|
|
|
+// // 开票到款日期
|
|
|
+// if req.TimeType > 0 && req.StartDate != "" && req.EndDate != "" {
|
|
|
+// st := fmt.Sprint(req.StartDate, " 00:00:00")
|
|
|
+// ed := fmt.Sprint(req.EndDate, " 23:59:59")
|
|
|
+// cond += ` AND a.invoice_type = ? AND (a.invoice_time BETWEEN ? AND ?)`
|
|
|
+// pars = append(pars, req.TimeType, st, ed)
|
|
|
+// }
|
|
|
+// // 已开票
|
|
|
+// if req.HasInvoice == 1 && req.HasPayment == 0 {
|
|
|
+// cond += ` AND a.invoice_type = 1`
|
|
|
+// }
|
|
|
+// // 已到款
|
|
|
+// if req.HasInvoice == 0 && req.HasPayment == 1 {
|
|
|
+// cond += ` AND a.invoice_type = 2`
|
|
|
+// }
|
|
|
+//
|
|
|
+// page := new(base.Page)
|
|
|
+// page.SetPageSize(req.PageSize)
|
|
|
+// page.SetCurrent(req.Current)
|
|
|
+// page.AddOrderItem(base.OrderItem{Column: "a.create_time", Asc: false})
|
|
|
+// page.AddOrderItem(base.OrderItem{Column: "b.contract_register_id", Asc: true})
|
|
|
+// if req.IsExport == 1 {
|
|
|
+// page.SetPageSize(10000)
|
|
|
+// page.SetCurrent(1)
|
|
|
+// }
|
|
|
+//
|
|
|
+// list, allRegisterIds, e := fms.GetInvoicePaymentCensusPageList(page, cond, pars)
|
|
|
+// if e != nil {
|
|
|
+// resp.FailMsg("获取失败", "获取商品到款统计列表失败, Err: "+e.Error(), c)
|
|
|
+// return
|
|
|
+// }
|
|
|
+// total := int64(len(allRegisterIds))
|
|
|
+// registerIds := make([]int, 0)
|
|
|
+// for i := range list {
|
|
|
+// registerIds = append(registerIds, list[i].ContractRegisterId)
|
|
|
+// }
|
|
|
+//
|
|
|
+// results := new(fms.InvoicePaymentCensusResp)
|
|
|
+// if len(registerIds) > 0 {
|
|
|
+// // 获取开票到款列表
|
|
|
+// ivCond := `contract_register_id IN ?`
|
|
|
+// ivPars := make([]interface{}, 0)
|
|
|
+// ivPars = append(ivPars, registerIds)
|
|
|
+// iv := new(fms.ContractInvoice)
|
|
|
+// invoiceList, e := iv.List(ivCond, ivPars, "")
|
|
|
+// if e != nil {
|
|
|
+// resp.FailMsg("获取失败", "获取开票到款列表失败, Err: "+e.Error(), c)
|
|
|
+// return
|
|
|
+// }
|
|
|
+// // 取出开票、到款
|
|
|
+// invoiceMap := make(map[int][]*fms.ContractInvoice, 0)
|
|
|
+// paymentMap := make(map[int][]*fms.ContractInvoice, 0)
|
|
|
+// paymentIds := make([]int, 0)
|
|
|
+// for i := range invoiceList {
|
|
|
+// if invoiceMap[invoiceList[i].ContractRegisterId] == nil {
|
|
|
+// invoiceMap[invoiceList[i].ContractRegisterId] = make([]*fms.ContractInvoice, 0)
|
|
|
+// }
|
|
|
+// if paymentMap[invoiceList[i].ContractRegisterId] == nil {
|
|
|
+// paymentMap[invoiceList[i].ContractRegisterId] = make([]*fms.ContractInvoice, 0)
|
|
|
+// }
|
|
|
+// if invoiceList[i].InvoiceType == fms.ContractInvoiceTypeMake {
|
|
|
+// invoiceMap[invoiceList[i].ContractRegisterId] = append(invoiceMap[invoiceList[i].ContractRegisterId], invoiceList[i])
|
|
|
+// }
|
|
|
+// if invoiceList[i].InvoiceType == fms.ContractInvoiceTypePay {
|
|
|
+// paymentMap[invoiceList[i].ContractRegisterId] = append(paymentMap[invoiceList[i].ContractRegisterId], invoiceList[i])
|
|
|
+// paymentIds = append(paymentIds, invoiceList[i].ContractInvoiceId)
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 合同套餐
|
|
|
+// contractServiceCond := `contract_register_id IN ?`
|
|
|
+// contractServicePars := make([]interface{}, 0)
|
|
|
+// contractServicePars = append(contractServicePars, registerIds)
|
|
|
+// contractServiceOB := new(fms.ContractService)
|
|
|
+// contractServiceList, e := contractServiceOB.List(contractServiceCond, contractServicePars)
|
|
|
+// if e != nil {
|
|
|
+// resp.FailMsg("获取失败", "获取合同套餐列表失败, Err:"+e.Error(), c)
|
|
|
+// return
|
|
|
+// }
|
|
|
+// contractServiceMap := make(map[int][]*fms.ContractService, 0)
|
|
|
+// servicesNameMap := make(map[int][]string, 0)
|
|
|
+// for i := range contractServiceList {
|
|
|
+// if contractServiceMap[contractServiceList[i].ContractRegisterId] == nil {
|
|
|
+// contractServiceMap[contractServiceList[i].ContractRegisterId] = make([]*fms.ContractService, 0)
|
|
|
+// }
|
|
|
+// contractServiceMap[contractServiceList[i].ContractRegisterId] = append(contractServiceMap[contractServiceList[i].ContractRegisterId], contractServiceList[i])
|
|
|
+// servicesNameMap[contractServiceList[i].ContractRegisterId] = append(servicesNameMap[contractServiceList[i].ContractRegisterId], contractServiceList[i].Title)
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 到款套餐分配
|
|
|
+// serviceAmountMap := make(map[int][]*fms.ContractPaymentServiceAmount, 0)
|
|
|
+// if len(paymentIds) > 0 {
|
|
|
+// serviceAmountCond := `contract_payment_id IN ?`
|
|
|
+// serviceAmountPars := make([]interface{}, 0)
|
|
|
+// serviceAmountPars = append(serviceAmountPars, paymentIds)
|
|
|
+// serviceAmountOB := new(fms.ContractPaymentServiceAmount)
|
|
|
+// serviceAmountList, e := serviceAmountOB.List(serviceAmountCond, serviceAmountPars)
|
|
|
+// if e != nil {
|
|
|
+// resp.FailMsg("获取失败", "获取到款套餐分配列表失败, Err:"+e.Error(), c)
|
|
|
+// return
|
|
|
+// }
|
|
|
+// for i := range serviceAmountList {
|
|
|
+// if serviceAmountMap[serviceAmountList[i].ContractRegisterId] == nil {
|
|
|
+// serviceAmountMap[serviceAmountList[i].ContractRegisterId] = make([]*fms.ContractPaymentServiceAmount, 0)
|
|
|
+// }
|
|
|
+// serviceAmountMap[serviceAmountList[i].ContractRegisterId] = append(serviceAmountMap[serviceAmountList[i].ContractRegisterId], serviceAmountList[i])
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 整合响应数据
|
|
|
+// respList := make([]*fms.InvoicePaymentCensusItem, 0)
|
|
|
+// for i := range list {
|
|
|
+// v := new(fms.InvoicePaymentCensusItem)
|
|
|
+// v.ContractRegisterId = list[i].ContractRegisterId
|
|
|
+// v.CompanyName = list[i].CompanyName
|
|
|
+// v.NewCompany = list[i].NewCompany
|
|
|
+// v.StartDate = list[i].StartDate.Format(utils.FormatDate)
|
|
|
+// v.EndDate = list[i].EndDate.Format(utils.FormatDate)
|
|
|
+// svList := servicesNameMap[list[i].ContractRegisterId]
|
|
|
+// v.ServicesName = strings.Join(svList, ",")
|
|
|
+// // 格式化(合并)开票到款数据
|
|
|
+// v.InvoicePaymentList = fmsService.MergeInvoiceList2InvoicePaymentCensusInfo(invoiceMap[list[i].ContractRegisterId], paymentMap[list[i].ContractRegisterId],
|
|
|
+// contractServiceMap[list[i].ContractRegisterId], serviceAmountMap[list[i].ContractRegisterId])
|
|
|
+// respList = append(respList, v)
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 开票到款金额合计(换算后)
|
|
|
+// amountTotalCond := `contract_register_id IN ?`
|
|
|
+// amountTotalPars := make([]interface{}, 0)
|
|
|
+// amountTotalPars = append(amountTotalPars, allRegisterIds)
|
|
|
+// amountTotalList, e := fms.GetContractInvoiceAmountTotal(amountTotalCond, amountTotalPars)
|
|
|
+// if e != nil {
|
|
|
+// resp.FailMsg("获取失败", "获取开票到款金额合计失败, Err:"+e.Error(), c)
|
|
|
+// return
|
|
|
+// }
|
|
|
+// amountTotalMap := make(map[int]float64)
|
|
|
+// for i := range amountTotalList {
|
|
|
+// amountTotalMap[amountTotalList[i].InvoiceType] = amountTotalList[i].TotalAmount
|
|
|
+// }
|
|
|
+// invoiceTotal, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", amountTotalMap[fms.ContractInvoiceTypeMake]), 64)
|
|
|
+// paymentTotal, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", amountTotalMap[fms.ContractInvoiceTypePay]), 64)
|
|
|
+//
|
|
|
+// // 分币种金额统计
|
|
|
+// currencyOB := new(fms.CurrencyUnit)
|
|
|
+// currencyCond := `enable = 1`
|
|
|
+// currencyPars := make([]interface{}, 0)
|
|
|
+// currencyList, e := currencyOB.List(currencyCond, currencyPars)
|
|
|
+// if e != nil {
|
|
|
+// resp.FailMsg("获取失败", "获取货币列表失败, Err: "+e.Error(), c)
|
|
|
+// return
|
|
|
+// }
|
|
|
+// unitMap := make(map[string]string)
|
|
|
+// invoiceCurrencyTotals := make([]*fms.InvoiceListCurrencyTotal, 0)
|
|
|
+// paymentCurrencyTotals := make([]*fms.InvoiceListCurrencyTotal, 0)
|
|
|
+// for i := range currencyList {
|
|
|
+// unitMap[currencyList[i].Code] = currencyList[i].UnitName
|
|
|
+// invoiceCurrencyTotals = append(invoiceCurrencyTotals, &fms.InvoiceListCurrencyTotal{
|
|
|
+// Name: currencyList[i].Name,
|
|
|
+// UnitName: currencyList[i].UnitName,
|
|
|
+// Code: currencyList[i].Code,
|
|
|
+// FlagImg: currencyList[i].FlagImg,
|
|
|
+// })
|
|
|
+// paymentCurrencyTotals = append(paymentCurrencyTotals, &fms.InvoiceListCurrencyTotal{
|
|
|
+// Name: currencyList[i].Name,
|
|
|
+// UnitName: currencyList[i].UnitName,
|
|
|
+// Code: currencyList[i].Code,
|
|
|
+// FlagImg: currencyList[i].FlagImg,
|
|
|
+// })
|
|
|
+// }
|
|
|
+// sumList, e := fms.GetInvoiceListCurrencySum(amountTotalCond, amountTotalPars, "currency_unit, invoice_type")
|
|
|
+// if e != nil {
|
|
|
+// resp.FailMsg("获取失败", "获取商品到款统计货币合计金额失败, Err: "+e.Error(), c)
|
|
|
+// return
|
|
|
+// }
|
|
|
+// invoiceSumMap := make(map[string]float64)
|
|
|
+// paymentSumMap := make(map[string]float64)
|
|
|
+// for i := range sumList {
|
|
|
+// if sumList[i].InvoiceType == fms.ContractInvoiceTypeMake {
|
|
|
+// invoiceSumMap[sumList[i].CurrencyUnit] = sumList[i].OriginAmountTotal
|
|
|
+// continue
|
|
|
+// }
|
|
|
+// if sumList[i].InvoiceType == fms.ContractInvoiceTypePay {
|
|
|
+// paymentSumMap[sumList[i].CurrencyUnit] = sumList[i].OriginAmountTotal
|
|
|
+// }
|
|
|
+// }
|
|
|
+// for i := range invoiceCurrencyTotals {
|
|
|
+// a, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", invoiceSumMap[invoiceCurrencyTotals[i].Code]), 64)
|
|
|
+// invoiceCurrencyTotals[i].Amount = a
|
|
|
+// }
|
|
|
+// for i := range paymentCurrencyTotals {
|
|
|
+// a, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", paymentSumMap[paymentCurrencyTotals[i].Code]), 64)
|
|
|
+// paymentCurrencyTotals[i].Amount = a
|
|
|
+// }
|
|
|
+//
|
|
|
+// results.DataList = respList
|
|
|
+// results.InvoiceTotal = invoiceTotal
|
|
|
+// results.PaymentTotal = paymentTotal
|
|
|
+// results.InvoiceCurrencyTotal = invoiceCurrencyTotals
|
|
|
+// results.PaymentCurrencyTotal = paymentCurrencyTotals
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 是否导出
|
|
|
+// if req.IsExport == 1 {
|
|
|
+// ExportInvoicePaymentCensusList(c, results)
|
|
|
+// return
|
|
|
+// }
|
|
|
+// page.SetTotal(total)
|
|
|
+// baseData := new(base.BaseData)
|
|
|
+// baseData.SetPage(page)
|
|
|
+// baseData.SetList(results)
|
|
|
+// resp.OkData("获取成功", baseData, c)
|
|
|
+//}
|
|
|
|
|
|
// ExportInvoicePaymentCensusList 导出商品到款统计列表
|
|
|
func ExportInvoicePaymentCensusList(c *gin.Context, results *fms.InvoicePaymentCensusResp) {
|
|
@@ -517,33 +516,45 @@ func (ct *InvoicePaymentController) List(c *gin.Context) {
|
|
|
|
|
|
results := new(fms.InvoicePaymentCensusResp)
|
|
|
if len(queryRegisterIds) > 0 {
|
|
|
- // 获取汇总数据
|
|
|
- summaryCond := `a.register_id IN ?`
|
|
|
- summaryPars := make([]interface{}, 0)
|
|
|
- summaryPars = append(summaryPars, queryRegisterIds)
|
|
|
- summaryList, e := fms.GetInvoicePaymentCensusSummaryData(summaryCond, summaryPars)
|
|
|
+ // 获取汇总数据IDs, 用于查询合计数据
|
|
|
+ summaryIdsCond := cond
|
|
|
+ summaryIdsPars := pars
|
|
|
+ summaryIds, e := fms.GetInvoicePaymentCensusSummaryDataIds(summaryIdsCond, summaryIdsPars)
|
|
|
if e != nil {
|
|
|
- resp.FailMsg("获取失败", "获取商品到款汇总列表失败, Err: "+e.Error(), c)
|
|
|
+ resp.FailMsg("获取失败", "获取商品到款汇总IDs失败, Err: "+e.Error(), c)
|
|
|
return
|
|
|
}
|
|
|
- summaryIds := make([]int, 0)
|
|
|
- paymentIds := make([]int, 0)
|
|
|
- for i := range summaryList {
|
|
|
- summaryIds = append(summaryIds, summaryList[i].SummaryId)
|
|
|
- if summaryList[i].PaymentId > 0 {
|
|
|
- paymentIds = append(paymentIds, summaryList[i].PaymentId)
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
var listErr, totalErr, totalGroupErr error
|
|
|
wg := sync.WaitGroup{}
|
|
|
|
|
|
// 响应列表
|
|
|
respList := make([]*fms.InvoicePaymentCensusItem, 0)
|
|
|
+ summaryList := make([]*fms.InvoicePaymentSummaryItem, 0)
|
|
|
wg.Add(1)
|
|
|
go func() {
|
|
|
defer wg.Done()
|
|
|
|
|
|
+ // 获取汇总数据
|
|
|
+ summaryCond := cond
|
|
|
+ summaryCond += ` AND a.register_id IN ?`
|
|
|
+ summaryPars := pars
|
|
|
+ summaryPars = append(summaryPars, queryRegisterIds)
|
|
|
+ summaryData, e := fms.GetInvoicePaymentCensusSummaryData(summaryCond, summaryPars)
|
|
|
+ if e != nil {
|
|
|
+ resp.FailMsg("获取失败", "获取商品到款汇总列表失败, Err: "+e.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ summaryList = summaryData
|
|
|
+ //summaryIds := make([]int, 0)
|
|
|
+ paymentIds := make([]int, 0)
|
|
|
+ for i := range summaryList {
|
|
|
+ //summaryIds = append(summaryIds, summaryList[i].SummaryId)
|
|
|
+ if summaryList[i].PaymentId > 0 {
|
|
|
+ paymentIds = append(paymentIds, summaryList[i].PaymentId)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// 合同套餐
|
|
|
contractServiceCond := `contract_register_id IN ?`
|
|
|
contractServicePars := make([]interface{}, 0)
|