|
@@ -1623,14 +1623,14 @@ func (ct *InvoicePaymentController) NotInvoiceList(c *gin.Context) {
|
|
|
page.SetCurrent(req.Current)
|
|
|
//排序
|
|
|
if req.SortType == "" {
|
|
|
- req.SortType = "desc"
|
|
|
+ req.SortType = "asc"
|
|
|
}
|
|
|
if req.SortType != "desc" && req.SortType != "asc" {
|
|
|
resp.Fail("排序类型不正确", c)
|
|
|
return
|
|
|
}
|
|
|
if req.SortParam == "" {
|
|
|
- page.AddOrderItem(base.OrderItem{Column: "e.start_date", Asc: false})
|
|
|
+ page.AddOrderItem(base.OrderItem{Column: "e.start_date", Asc: true})
|
|
|
} else if req.SortParam == "start_date" {
|
|
|
if req.SortType == "asc" {
|
|
|
page.AddOrderItem(base.OrderItem{Column: "e.start_date", Asc: true})
|
|
@@ -1653,28 +1653,42 @@ func (ct *InvoicePaymentController) NotInvoiceList(c *gin.Context) {
|
|
|
page.SetCurrent(1)
|
|
|
}
|
|
|
|
|
|
+ cond += ` AND b.contract_amount <> b.invoiced_amount `
|
|
|
registerList, total, e := fms.GetInvoiceCensusPageList(page, cond, pars)
|
|
|
if e != nil {
|
|
|
resp.FailMsg("获取失败", "获取商品到款统计列表总数失败, Err: "+e.Error(), c)
|
|
|
return
|
|
|
}
|
|
|
queryRegisterIds := make([]int, 0)
|
|
|
- for i := range registerList {
|
|
|
- queryRegisterIds = append(queryRegisterIds, registerList[i].ContractRegisterId)
|
|
|
+ for _, v := range registerList {
|
|
|
+ queryRegisterIds = append(queryRegisterIds, v.ContractRegisterId)
|
|
|
}
|
|
|
-
|
|
|
//fmt.Println("queryRegisterIds:",queryRegisterIds)
|
|
|
results := new(fms.NotInvoicePaymentCensusResp)
|
|
|
if len(queryRegisterIds) > 0 {
|
|
|
+ // 获取合同的套餐金额信息
|
|
|
+ serviceAmountList, e := fms.GetContractServiceAmountByContractRegisterIds(queryRegisterIds)
|
|
|
+ if e != nil {
|
|
|
+ resp.FailData("获取合同的套餐金额信息失败", "Err:"+e.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ serviceAmountMap := make(map[int]map[int]*fms.ContractServiceAmount, 0)
|
|
|
+ for _, v := range serviceAmountList {
|
|
|
+ if _, ok := serviceAmountMap[v.ContractRegisterId]; !ok {
|
|
|
+ serviceAmountMap[v.ContractRegisterId] = make(map[int]*fms.ContractServiceAmount)
|
|
|
+ }
|
|
|
+ serviceAmountMap[v.ContractRegisterId][v.ProductId] = v
|
|
|
+ }
|
|
|
+
|
|
|
// 获取汇总数据IDs, 用于查询合计数据
|
|
|
summaryIdsCond := cond
|
|
|
summaryIdsPars := pars
|
|
|
if req.SellerIds != "" {
|
|
|
sellerIds := strings.Split(req.SellerIds, ",")
|
|
|
- summaryIdsCond += ` AND c.seller_id in ? AND a.payment_id <> 0 AND a.invoice_id = 0 AND (c.origin_amount > d.origin_amount OR d.origin_amount IS NULL) `
|
|
|
+ summaryIdsCond += ` AND c.seller_id in ? AND (d.origin_amount > c.origin_amount OR c.origin_amount IS NULL) `
|
|
|
summaryIdsPars = append(summaryIdsPars, sellerIds)
|
|
|
} else {
|
|
|
- summaryIdsCond += ` AND a.payment_id <> 0 AND a.invoice_id = 0 AND (c.origin_amount > d.origin_amount OR d.origin_amount IS NULL) `
|
|
|
+ summaryIdsCond += ` AND (d.origin_amount > c.origin_amount OR c.origin_amount IS NULL) `
|
|
|
summaryIdsPars = append(summaryIdsPars)
|
|
|
}
|
|
|
summaryIds, e := fms.GetInvoicePaymentCensusSummaryDataIds(summaryIdsCond, summaryIdsPars)
|
|
@@ -1689,7 +1703,7 @@ func (ct *InvoicePaymentController) NotInvoiceList(c *gin.Context) {
|
|
|
|
|
|
// 响应列表
|
|
|
respList := make([]*fms.NotPaymentCensusItem, 0)
|
|
|
- summaryList := make([]*fms.InvoicePaymentSummaryItem, 0)
|
|
|
+ summaryList := make([]*fms.NotInvoicePaymentSummaryItem, 0)
|
|
|
wg.Add(1)
|
|
|
go func() {
|
|
|
defer wg.Done()
|
|
@@ -1699,124 +1713,43 @@ func (ct *InvoicePaymentController) NotInvoiceList(c *gin.Context) {
|
|
|
summaryCond += ` AND a.register_id IN ?`
|
|
|
summaryPars := pars
|
|
|
summaryPars = append(summaryPars, queryRegisterIds)
|
|
|
- if req.SellerIds != "" {
|
|
|
- sellerIds := strings.Split(req.SellerIds, ",")
|
|
|
- summaryCond += ` AND d.seller_id in ? AND a.payment_id <> 0 AND a.invoice_id = 0 `
|
|
|
- summaryPars = append(summaryPars, sellerIds, sellerIds)
|
|
|
- } else {
|
|
|
- summaryCond += ` AND a.payment_id <> 0 AND a.invoice_id = 0 `
|
|
|
- summaryPars = append(summaryPars)
|
|
|
- }
|
|
|
+ //if req.SellerIds != "" {
|
|
|
+ // sellerIds := strings.Split(req.SellerIds, ",")
|
|
|
+ // summaryCond += ` AND c.seller_id in ? AND a.payment_id <> 0 AND (d.origin_amount > c.origin_amount OR c.origin_amount IS NULL) `
|
|
|
+ // summaryPars = append(summaryPars, sellerIds, sellerIds)
|
|
|
+ //} else {
|
|
|
+ // summaryCond += ` AND a.payment_id <> 0 AND (d.origin_amount > c.origin_amount OR c.origin_amount IS NULL) `
|
|
|
+ // summaryPars = append(summaryPars)
|
|
|
+ //}
|
|
|
|
|
|
- summaryData, e := fms.GetInvoicePaymentCensusSummaryData(summaryCond, summaryPars)
|
|
|
+ summaryData, e := fms.GetNotInvoicePaymentCensusSummaryData(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)
|
|
|
- }
|
|
|
- }
|
|
|
- fmt.Println("paymentIds:", paymentIds)
|
|
|
- // 合同套餐
|
|
|
- /*contractServiceCond := `contract_register_id IN ?`
|
|
|
- contractServicePars := make([]interface{}, 0)
|
|
|
- contractServicePars = append(contractServicePars, queryRegisterIds)
|
|
|
- contractServiceOB := new(fms.ContractService)
|
|
|
- contractServiceList, e := contractServiceOB.List(contractServiceCond, contractServicePars)
|
|
|
- if e != nil {
|
|
|
- listErr = fmt.Errorf("获取合同套餐列表失败, Err: %s", e.Error())
|
|
|
- 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)
|
|
|
- }
|
|
|
- */
|
|
|
- servicesNameMap, serviceFormatMap, e := fmsService.GetContractServiceNameFormat(queryRegisterIds)
|
|
|
- if e != nil {
|
|
|
- listErr = fmt.Errorf("获取合同套餐列表失败, Err: %s", e.Error())
|
|
|
- return
|
|
|
- }
|
|
|
- // 到款套餐分配
|
|
|
- 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 {
|
|
|
- listErr = fmt.Errorf("获取到款套餐分配列表失败, Err: %s", e.Error())
|
|
|
- return
|
|
|
- }
|
|
|
- for i := range serviceAmountList {
|
|
|
- if serviceAmountMap[serviceAmountList[i].ContractPaymentId] == nil {
|
|
|
- serviceAmountMap[serviceAmountList[i].ContractPaymentId] = make([]*fms.ContractPaymentServiceAmount, 0)
|
|
|
- }
|
|
|
- serviceAmountMap[serviceAmountList[i].ContractPaymentId] = append(serviceAmountMap[serviceAmountList[i].ContractPaymentId], serviceAmountList[i])
|
|
|
- }
|
|
|
+ //paymentIds := make([]int, 0)
|
|
|
+ //for i := range summaryList {
|
|
|
+ // //summaryIds = append(summaryIds, summaryList[i].SummaryId)
|
|
|
+ //}
|
|
|
+ NotInvoiceSummaryMap := make(map[int][]*fms.NotInvoicePaymentSummaryItem, 0)
|
|
|
+ for _, v := range summaryList {
|
|
|
+ NotInvoiceSummaryMap[v.RegisterId] = append(NotInvoiceSummaryMap[v.RegisterId], v)
|
|
|
}
|
|
|
|
|
|
// 重组汇总数据
|
|
|
summaryMap := make(map[int][]*fms.NotPaymentCensusInfo)
|
|
|
- amountMap := make(map[string]*fms.ContractPaymentServiceAmount)
|
|
|
- for i := range summaryList {
|
|
|
- v := new(fms.NotPaymentCensusInfo)
|
|
|
- v.InvoiceId = summaryList[i].InvoiceId
|
|
|
- v.InvoiceDate = utils.TimeTransferString(utils.FormatDate, summaryList[i].InvoiceDate)
|
|
|
- v.InvoiceAmount = summaryList[i].InvoiceAmount
|
|
|
- v.SellerId = summaryList[i].SellerId
|
|
|
- v.SellerName = summaryList[i].SellerName
|
|
|
- v.SellerGroupId = summaryList[i].SellerGroupId
|
|
|
- v.SellerGroupName = summaryList[i].SellerGroupName
|
|
|
- v.SellerType = summaryList[i].ServiceProductId
|
|
|
- v.PaymentId = summaryList[i].PaymentId
|
|
|
- v.PaymentDate = utils.TimeTransferString(utils.FormatDate, summaryList[i].PaymentDate)
|
|
|
- v.PaymentAmount = summaryList[i].PaymentAmount
|
|
|
- v.PayType = summaryList[i].PayType
|
|
|
- // 套餐到款分配
|
|
|
- svaList := make([]*fms.ContractPaymentServiceAmountItem, 0)
|
|
|
- amountList := serviceAmountMap[summaryList[i].PaymentId]
|
|
|
- if amountList != nil {
|
|
|
- for i := range amountList {
|
|
|
- k := fmt.Sprintf("%d-%d", amountList[i].ContractPaymentId, amountList[i].ServiceTemplateId)
|
|
|
- amountMap[k] = amountList[i]
|
|
|
- }
|
|
|
- }
|
|
|
- // 合同对应的所有套餐
|
|
|
- svList := serviceFormatMap[summaryList[i].RegisterId]
|
|
|
- if svList != nil {
|
|
|
- for ii := range svList {
|
|
|
- vv := new(fms.ContractPaymentServiceAmountItem)
|
|
|
- vv.ServiceTemplateId = svList[ii].ServiceTemplateId
|
|
|
- vv.ServiceTemplateName = svList[ii].FormatTitle
|
|
|
- vv.ServiceTemplatePid = svList[ii].ServiceTemplatePid
|
|
|
- k2 := fmt.Sprintf("%d-%d", summaryList[i].PaymentId, svList[ii].ServiceTemplateId)
|
|
|
- a := amountMap[k2]
|
|
|
- if a != nil {
|
|
|
- vv.ContractPaymentServiceAmountId = a.ContractPaymentServiceAmountId
|
|
|
- vv.ContractPaymentId = a.ContractPaymentId
|
|
|
- vv.Amount = a.Amount
|
|
|
- }
|
|
|
- svaList = append(svaList, vv)
|
|
|
- }
|
|
|
- }
|
|
|
- v.ServiceAmountList = svaList
|
|
|
-
|
|
|
- summaryMap[summaryList[i].SummaryId] = append(summaryMap[summaryList[i].SummaryId], v)
|
|
|
+ sellerList, e := crmService.GetSellerDepartmentListWithGroupAndTeam()
|
|
|
+ if e != nil {
|
|
|
+ resp.FailData("获取销售失败", "Err:"+e.Error(), c)
|
|
|
+ return
|
|
|
}
|
|
|
-
|
|
|
+ sellerMap := make(map[int]*crm.SellerAdminWithGroupTeam)
|
|
|
+ for i := range sellerList {
|
|
|
+ sellerMap[sellerList[i].SellerId] = sellerList[i]
|
|
|
+ }
|
|
|
+ sellerTypeMap := map[int]string{2: "FICC销售", 5: "权益销售"}
|
|
|
// 货币列表
|
|
|
currencyOB := new(fms.CurrencyUnit)
|
|
|
currencyCond := `enable = 1`
|
|
@@ -1831,6 +1764,32 @@ func (ct *InvoicePaymentController) NotInvoiceList(c *gin.Context) {
|
|
|
unitMap[currencyList[i].Code] = currencyList[i].UnitName
|
|
|
}
|
|
|
|
|
|
+ for registerId, list := range NotInvoiceSummaryMap {
|
|
|
+ for _, v := range list {
|
|
|
+ v.NotInvoicedAmountTotal = serviceAmountMap[registerId][v.ServiceProductId].ServiceAmount - v.InvoiceAmountTotal
|
|
|
+
|
|
|
+ if v.SellerId > 0 && v.RaiSellerId > 0 {
|
|
|
+ if v.ServiceProductId == 1 {
|
|
|
+ v.SellerGroupId = sellerMap[v.SellerId].GroupId
|
|
|
+ v.SellerGroupName = sellerMap[v.SellerId].GroupName
|
|
|
+ v.SellerType = sellerTypeMap[sellerMap[v.SellerId].DepartmentId]
|
|
|
+ } else {
|
|
|
+ v.RaiSellerGroupId = sellerMap[v.RaiSellerId].GroupId
|
|
|
+ v.RaiSellerGroupName = sellerMap[v.RaiSellerId].GroupName
|
|
|
+ v.SellerType = sellerTypeMap[sellerMap[v.RaiSellerId].DepartmentId]
|
|
|
+ }
|
|
|
+ } else if v.SellerId > 0 && v.RaiSellerId == 0{
|
|
|
+ v.SellerGroupId = sellerMap[v.SellerId].GroupId
|
|
|
+ v.SellerGroupName = sellerMap[v.SellerId].GroupName
|
|
|
+ v.SellerType = sellerTypeMap[sellerMap[v.SellerId].DepartmentId]
|
|
|
+ }else if v.SellerId == 0 && v.RaiSellerId > 0 {
|
|
|
+ v.RaiSellerGroupId = sellerMap[v.RaiSellerId].GroupId
|
|
|
+ v.RaiSellerGroupName = sellerMap[v.RaiSellerId].GroupName
|
|
|
+ v.SellerType = sellerTypeMap[sellerMap[v.RaiSellerId].DepartmentId]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// 响应列表
|
|
|
for i := range registerList {
|
|
|
v := new(fms.NotPaymentCensusItem)
|
|
@@ -1840,14 +1799,19 @@ func (ct *InvoicePaymentController) NotInvoiceList(c *gin.Context) {
|
|
|
v.NewCompany = registerList[i].NewCompany
|
|
|
v.StartDate = utils.TimeTransferString(utils.FormatDate, registerList[i].StartDate)
|
|
|
v.EndDate = utils.TimeTransferString(utils.FormatDate, registerList[i].EndDate)
|
|
|
- v.ServicesName = servicesNameMap[registerList[i].ContractRegisterId]
|
|
|
v.InvoicePaymentList = summaryMap[registerList[i].SummaryId]
|
|
|
v.ContractType = registerList[i].ContractType
|
|
|
v.ContractCode = registerList[i].ContractCode
|
|
|
v.ContractAmount = registerList[i].ContractAmount
|
|
|
v.UnitName = unitMap[registerList[i].CurrencyUnit]
|
|
|
v.ProductIds = registerList[i].ProductIds
|
|
|
- v.NotInvoiceTotal = registerList[i].ContractAmount - registerList[i].InvoicedAmount
|
|
|
+ if registerList[i].InvoicedAmount != 0 {
|
|
|
+ v.NotInvoiceTotal = registerList[i].ContractAmount - registerList[i].InvoicedAmount
|
|
|
+ } else {
|
|
|
+ v.NotInvoiceTotal = registerList[i].ContractAmount - registerList[i].PaymentAmount
|
|
|
+ }
|
|
|
+
|
|
|
+ v.NotInvoiceList = NotInvoiceSummaryMap[summaryList[i].RegisterId]
|
|
|
respList = append(respList, v)
|
|
|
}
|
|
|
}()
|
|
@@ -2211,7 +2175,16 @@ func (ct *InvoicePaymentController) NotPaymentList(c *gin.Context) {
|
|
|
// }
|
|
|
// serviceAmountMap[v.ContractRegisterId][v.ProductId] = v
|
|
|
//}
|
|
|
-
|
|
|
+ sellerList, e := crmService.GetSellerDepartmentListWithGroupAndTeam()
|
|
|
+ if e != nil {
|
|
|
+ resp.FailData("获取销售失败", "Err:"+e.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ sellerMap := make(map[int]*crm.SellerAdminWithGroupTeam)
|
|
|
+ for i := range sellerList {
|
|
|
+ sellerMap[sellerList[i].SellerId] = sellerList[i]
|
|
|
+ }
|
|
|
+ sellerTypeMap := map[int]int{crm.SellerDepartmentId: 1, crm.RaiSellerDepartmentId: 2}
|
|
|
// 重组汇总数据
|
|
|
summaryMap := make(map[int][]*fms.NotPaymentCensusInfo)
|
|
|
for i := range summaryList {
|
|
@@ -2223,7 +2196,7 @@ func (ct *InvoicePaymentController) NotPaymentList(c *gin.Context) {
|
|
|
v.SellerName = summaryList[i].SellerName
|
|
|
v.SellerGroupId = summaryList[i].SellerGroupId
|
|
|
v.SellerGroupName = summaryList[i].SellerGroupName
|
|
|
- v.SellerType = summaryList[i].ServiceProductId
|
|
|
+ v.SellerType = sellerTypeMap[sellerMap[summaryList[i].SellerId].DepartmentId]
|
|
|
v.PaymentId = summaryList[i].PaymentId
|
|
|
v.PaymentDate = utils.TimeTransferString(utils.FormatDate, summaryList[i].PaymentDate)
|
|
|
v.PaymentAmount = summaryList[i].PaymentAmount
|
|
@@ -2437,6 +2410,73 @@ func ExportNotInvoiceCensusList(c *gin.Context, results *fms.NotInvoicePaymentCe
|
|
|
resp.Fail("列表数据为空", c)
|
|
|
return
|
|
|
}
|
|
|
+ // 生成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{"序号", "客户名称", "合同编号", "合同开始时间", "合同结束时间","合同金额","金额单位", "未开票金额", "套餐类型", "销售", "销售组别","销售类型"}
|
|
|
+ titleRow := sheet.AddRow()
|
|
|
+ for i := range rowTitle {
|
|
|
+ v := titleRow.AddCell()
|
|
|
+ v.SetString(rowTitle[i])
|
|
|
+ v.SetStyle(style)
|
|
|
+ }
|
|
|
+ incomeSummaryItemList := make([]*fms.NotPaymentCensusItem, 0)
|
|
|
+ incomeSummaryItemList = list
|
|
|
+ // 填充数据
|
|
|
+ for i, v := range incomeSummaryItemList {
|
|
|
+ dataRow := sheet.AddRow()
|
|
|
+ dataRow.AddCell().SetString(strconv.Itoa(i)) //序号
|
|
|
+ dataRow.AddCell().SetString(v.CompanyName) // 客户名称
|
|
|
+ dataRow.AddCell().SetString(v.ContractCode) // 合同编号
|
|
|
+ dataRow.AddCell().SetString(v.StartDate) // 合同开始时间
|
|
|
+ dataRow.AddCell().SetString(v.EndDate) // 合同结束时间
|
|
|
+ dataRow.AddCell().SetString(v.ContractCode) // 合同金额
|
|
|
+ dataRow.AddCell().SetString(v.UnitName) // 金额单位
|
|
|
+ sheet.AddRow()
|
|
|
+ for _, item := range v.NotInvoiceList {
|
|
|
+ dataRow.AddCell().SetString(fmt.Sprintf("%.2f",item.NotInvoicedAmountTotal)) // 未开票金额
|
|
|
+ dataRow.AddCell().SetString(strconv.Itoa(item.ServiceProductId)) // 套餐类型
|
|
|
+ dataRow.AddCell().SetString(item.SellerName) // 销售
|
|
|
+ dataRow.AddCell().SetString(item.SellerGroupName) // 销售组别
|
|
|
+ dataRow.AddCell().SetString(item.SellerType) // 销售类型
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 输出文件
|
|
|
+ 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)
|
|
|
+}
|
|
|
+
|
|
|
+// ExportNotPaymentCensusList 导出开票未到款统计列表
|
|
|
+func ExportNotPaymentCensusList(c *gin.Context, results *fms.NotInvoicePaymentCensusResp) {
|
|
|
+ list := results.DataList
|
|
|
+ if len(list) == 0 {
|
|
|
+ resp.Fail("列表数据为空", c)
|
|
|
+ return
|
|
|
+ }
|
|
|
|
|
|
// 生成Excel文件
|
|
|
xlsxFile := xlsx.NewFile()
|
|
@@ -2449,7 +2489,7 @@ func ExportNotInvoiceCensusList(c *gin.Context, results *fms.NotInvoicePaymentCe
|
|
|
style.Alignment = alignment
|
|
|
style.ApplyAlignment = true
|
|
|
|
|
|
- sheet, err := xlsxFile.AddSheet("未开票统计")
|
|
|
+ sheet, err := xlsxFile.AddSheet("开票未到款统计")
|
|
|
if err != nil {
|
|
|
resp.FailData("新增Sheet失败", "Err:"+err.Error(), c)
|
|
|
return
|
|
@@ -2460,9 +2500,9 @@ func ExportNotInvoiceCensusList(c *gin.Context, results *fms.NotInvoicePaymentCe
|
|
|
// 前三行-开票金额合计
|
|
|
rowA := sheet.AddRow()
|
|
|
cellAA := rowA.AddCell()
|
|
|
- cellAA.SetString(fmt.Sprintf("未开票合计金额(换算后):%.2f(元)", results.NotInvoiceTotal))
|
|
|
- rowBData := "未开票金额:"
|
|
|
- for _, v := range results.NotInvoiceCurrencyTotal {
|
|
|
+ cellAA.SetString(fmt.Sprintf("开票未到款合计金额(换算后):%.2f(元)", results.InvoiceTotal))
|
|
|
+ rowBData := "已开票金额:"
|
|
|
+ for _, v := range results.InvoiceCurrencyTotal {
|
|
|
rowBData += fmt.Sprintf("%s%.2f(%s) ", v.Name, v.Amount, v.UnitName)
|
|
|
}
|
|
|
rowB := sheet.AddRow()
|
|
@@ -2640,650 +2680,3 @@ func ExportNotInvoiceCensusList(c *gin.Context, results *fms.NotInvoicePaymentCe
|
|
|
http.ServeContent(c.Writer, c.Request, fileName, time.Now(), content)
|
|
|
}
|
|
|
|
|
|
-// ExportNotPaymentCensusList 导出开票未到款统计列表
|
|
|
-func ExportNotPaymentCensusList(c *gin.Context, results *fms.NotInvoicePaymentCensusResp) {
|
|
|
- list := results.DataList
|
|
|
- if len(list) == 0 {
|
|
|
- resp.Fail("列表数据为空", c)
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- // 生成Excel文件
|
|
|
- xlsxFile := xlsx.NewFile()
|
|
|
- style := xlsx.NewStyle()
|
|
|
- alignment := xlsx.Alignment{
|
|
|
- Horizontal: "center",
|
|
|
- Vertical: "center",
|
|
|
- WrapText: true,
|
|
|
- }
|
|
|
- style.Alignment = alignment
|
|
|
- style.ApplyAlignment = true
|
|
|
-
|
|
|
- sheet, err := xlsxFile.AddSheet("开票未到款统计")
|
|
|
- if err != nil {
|
|
|
- resp.FailData("新增Sheet失败", "Err:"+err.Error(), c)
|
|
|
- return
|
|
|
- }
|
|
|
- _ = sheet.SetColWidth(1, 1, 30)
|
|
|
- _ = sheet.SetColWidth(3, 3, 30)
|
|
|
-
|
|
|
- // 前三行-开票金额合计
|
|
|
- rowA := sheet.AddRow()
|
|
|
- cellAA := rowA.AddCell()
|
|
|
- cellAA.SetString(fmt.Sprintf("开票未到款合计金额(换算后):%.2f(元)", results.InvoiceTotal))
|
|
|
- rowBData := "已开票金额:"
|
|
|
- for _, v := range results.InvoiceCurrencyTotal {
|
|
|
- rowBData += fmt.Sprintf("%s%.2f(%s) ", v.Name, v.Amount, v.UnitName)
|
|
|
- }
|
|
|
- rowB := sheet.AddRow()
|
|
|
- rowB.AddCell().SetString(rowBData)
|
|
|
- sheet.AddRow()
|
|
|
-
|
|
|
- // 表头, 套餐动态获取
|
|
|
- rowTitle := []string{"序号", "客户名称", "是否新客户", "合同有效期", "开票日", "开票金额", "到款日", "到款金额", "付款方式", "销售",
|
|
|
- "销售组别", "销售类型"}
|
|
|
- serviceTempCond := ``
|
|
|
- serviceTempPars := make([]interface{}, 0)
|
|
|
- serviceTempOB := new(fms.ContractServiceTemplate)
|
|
|
- serviceTempList, e := serviceTempOB.List(serviceTempCond, serviceTempPars)
|
|
|
- if e != nil {
|
|
|
- resp.FailData("获取套餐模板列表失败", "Err:"+e.Error(), c)
|
|
|
- return
|
|
|
- }
|
|
|
- serviceTempListMap := make(map[int]*fms.ContractServiceTemplate)
|
|
|
- var serviceTempShow []*fms.ContractServiceTemplate
|
|
|
- for i := range serviceTempList {
|
|
|
- serviceTempListMap[serviceTempList[i].ServiceTemplateId] = serviceTempList[i]
|
|
|
- }
|
|
|
- for i := range serviceTempList {
|
|
|
- if serviceTempList[i].ProductId == 1 {
|
|
|
- rowTitle = append(rowTitle, serviceTempList[i].Title)
|
|
|
- serviceTempShow = append(serviceTempShow, serviceTempList[i])
|
|
|
- } else if serviceTempList[i].ProductId == 2 {
|
|
|
- if serviceTempList[i].Title == "行业套餐" || serviceTempList[i].Title == "权益大套餐" || (serviceTempList[i].Title == "策略" && serviceTempListMap[serviceTempList[i].Pid].Pid == 0) {
|
|
|
- } else if serviceTempList[i].Title == "医药" || serviceTempList[i].Title == "消费" || serviceTempList[i].Title == "科技" || serviceTempList[i].Title == "智造" {
|
|
|
- } else {
|
|
|
- serviceTempShow = append(serviceTempShow, serviceTempList[i])
|
|
|
- }
|
|
|
- if serviceTempList[i].Title == "行业套餐" || serviceTempList[i].Title == "45万" || serviceTempList[i].Title == "70万" {
|
|
|
- continue
|
|
|
- }
|
|
|
-
|
|
|
- if serviceTempList[i].Pid > 0 && serviceTempListMap[serviceTempList[i].Pid].Pid > 0 {
|
|
|
- continue
|
|
|
- }
|
|
|
-
|
|
|
- rowTitle = append(rowTitle, serviceTempList[i].Title)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- hi := 0
|
|
|
- insertHi := 0
|
|
|
- titleRow := sheet.AddRow()
|
|
|
- for i := range rowTitle {
|
|
|
- v := titleRow.AddCell()
|
|
|
- v.SetString(rowTitle[i])
|
|
|
- v.SetStyle(style)
|
|
|
- if rowTitle[i] != "权益大套餐" && rowTitle[i] != "医药" && rowTitle[i] != "消费" && rowTitle[i] != "科技" && rowTitle[i] != "智造" {
|
|
|
- v.VMerge = 1
|
|
|
- hi++
|
|
|
- } else {
|
|
|
- if insertHi == 0 {
|
|
|
- insertHi = hi
|
|
|
- }
|
|
|
- v.HMerge = 1
|
|
|
- titleRow.AddCell().SetString("")
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 新增一行放主观和客观
|
|
|
- specialRow := sheet.AddRow()
|
|
|
- for i := 0; i < hi; i++ {
|
|
|
- if i == insertHi {
|
|
|
- v1 := specialRow.AddCell()
|
|
|
- v1.SetString("45万")
|
|
|
- v1.SetStyle(style)
|
|
|
- v1 = specialRow.AddCell()
|
|
|
- v1.SetString("70万")
|
|
|
- v1.SetStyle(style)
|
|
|
- for j := 0; j < 8; j++ {
|
|
|
- if j%2 == 0 {
|
|
|
- v1 = specialRow.AddCell()
|
|
|
- v1.SetString("主观")
|
|
|
- v1.SetStyle(style)
|
|
|
- } else {
|
|
|
- v1 = specialRow.AddCell()
|
|
|
- v1.SetString("客观")
|
|
|
- v1.SetStyle(style)
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- v := specialRow.AddCell()
|
|
|
- v.SetString("")
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- newCompanyMap := map[int]string{0: "否", 1: "是"}
|
|
|
- sellerTypeMap := map[int]string{1: "FICC销售", 2: "权益销售"}
|
|
|
- for k, v := range list {
|
|
|
- dataRow := sheet.AddRow()
|
|
|
- // 前四个单元格根据每行开票到款条数向下合并
|
|
|
- l := len(v.InvoicePaymentList)
|
|
|
- mergeRowNum := l - 1
|
|
|
- // 序号
|
|
|
- sortNum := k + 1
|
|
|
- colA := dataRow.AddCell()
|
|
|
- colA.VMerge = mergeRowNum
|
|
|
- colA.SetString(fmt.Sprint(sortNum))
|
|
|
- // 客户名称
|
|
|
- colB := dataRow.AddCell()
|
|
|
- colB.VMerge = mergeRowNum
|
|
|
- colB.SetString(v.CompanyName)
|
|
|
- // 是否新客户
|
|
|
- colC := dataRow.AddCell()
|
|
|
- colC.VMerge = mergeRowNum
|
|
|
- colC.SetString(newCompanyMap[v.NewCompany])
|
|
|
- // 合同有效期
|
|
|
- colD := dataRow.AddCell()
|
|
|
- colD.VMerge = mergeRowNum
|
|
|
- colD.SetString(fmt.Sprint(v.StartDate, "至", v.EndDate))
|
|
|
- // 开票到款信息
|
|
|
- for k2, v2 := range v.InvoicePaymentList {
|
|
|
- rowData := []string{
|
|
|
- v2.InvoiceDate, // 开票日
|
|
|
- fmt.Sprint(v2.InvoiceAmount), // 开票金额
|
|
|
- v2.PaymentDate, // 到款日
|
|
|
- fmt.Sprint(v2.PaymentAmount), // 到款金额
|
|
|
- fms.ContractPaymentPayTypeNameMap[v2.PayType], // 付款方式
|
|
|
- v2.SellerName, // 销售
|
|
|
- v2.SellerGroupName, // 组别
|
|
|
- sellerTypeMap[v2.SellerType], // 销售类型
|
|
|
- }
|
|
|
- // 套餐金额信息
|
|
|
- serviceTempShowAmount := make(map[int]string)
|
|
|
- for i := range serviceTempShow {
|
|
|
- for s2 := range v2.ServiceAmountList {
|
|
|
- item := v2.ServiceAmountList[s2]
|
|
|
- if item.ServiceTemplateId == serviceTempShow[i].ServiceTemplateId {
|
|
|
- serviceTempShowAmount[serviceTempShow[i].ServiceTemplateId] = fmt.Sprint(item.Amount)
|
|
|
- break
|
|
|
- } else if serviceTempShow[i].Pid == item.ServiceTemplateId {
|
|
|
- serviceTempShowAmount[serviceTempShow[i].ServiceTemplateId] = fmt.Sprint(item.Amount / 2)
|
|
|
- break
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- for i := range serviceTempShow {
|
|
|
- sa := ""
|
|
|
- if am, ok := serviceTempShowAmount[serviceTempShow[i].ServiceTemplateId]; ok {
|
|
|
- sa = am
|
|
|
- }
|
|
|
- rowData = append(rowData, sa)
|
|
|
- }
|
|
|
- // 首行开票到款
|
|
|
- if k2 == 0 {
|
|
|
- for i := range rowData {
|
|
|
- dataRow.AddCell().SetString(rowData[i])
|
|
|
- }
|
|
|
- continue
|
|
|
- }
|
|
|
- // 其他行开票到款, 加四列空的单元格用于合并
|
|
|
- dataRowExtra := sheet.AddRow()
|
|
|
- for i := 0; i < 4; i++ {
|
|
|
- dataRowExtra.AddCell()
|
|
|
- }
|
|
|
- for i := range rowData {
|
|
|
- dataRowExtra.AddCell().SetString(rowData[i])
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 输出文件
|
|
|
- var buffer bytes.Buffer
|
|
|
- _ = xlsxFile.Write(&buffer)
|
|
|
- content := bytes.NewReader(buffer.Bytes())
|
|
|
- randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
|
|
|
- fileName := "商品到款统计_" + 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)
|
|
|
-}
|
|
|
-
|
|
|
-func (ct *InvoicePaymentController) NotInvoiceList2(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 b.contract_code LIKE ?)`
|
|
|
- pars = append(pars, kw, kw)
|
|
|
- }
|
|
|
- if req.SellerIds != "" {
|
|
|
- sellerIds := strings.Split(req.SellerIds, ",")
|
|
|
- cond += ` AND (c.seller_id in ?)`
|
|
|
- pars = append(pars, sellerIds)
|
|
|
- }
|
|
|
- // 套餐筛选
|
|
|
- if req.ServiceTypes != "" {
|
|
|
- serviceTypes := strings.Split(req.ServiceTypes, ",")
|
|
|
- tempRegisterIds, e := fms.GetContractRegisterIdsByTempId(serviceTypes)
|
|
|
- if e != nil {
|
|
|
- resp.FailMsg("获取失败", "获取合同登记IDs失败, Err: "+e.Error(), c)
|
|
|
- return
|
|
|
- }
|
|
|
- if len(tempRegisterIds) > 0 {
|
|
|
- cond += ` AND a.register_id IN ?`
|
|
|
- pars = append(pars, tempRegisterIds)
|
|
|
- } else {
|
|
|
- cond += ` AND 1 = 2`
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if req.ListParam == 1 {
|
|
|
- cond += ` AND a.service_product_id = 1 `
|
|
|
- } else if req.ListParam == 2 {
|
|
|
- cond += ` AND a.service_product_id = 2 `
|
|
|
- }
|
|
|
-
|
|
|
- // 开票到款日期
|
|
|
- //if req.TimeType != 0 {
|
|
|
- // if req.TimeType == 1 && req.StartDate != "" && req.EndDate != "" {
|
|
|
- // st := fmt.Sprint(req.StartDate, " 00:00:00")
|
|
|
- // ed := fmt.Sprint(req.EndDate, " 23:59:59")
|
|
|
- // cond += ` AND (c.invoice_time BETWEEN ? AND ?) `
|
|
|
- // pars = append(pars, st, ed)
|
|
|
- // }else if req.TimeType == 2 && req.StartDate != "" && req.EndDate != "" {
|
|
|
- // st := fmt.Sprint(req.StartDate, " 00:00:00")
|
|
|
- // ed := fmt.Sprint(req.EndDate, " 23:59:59")
|
|
|
- // cond += ` AND (d.invoice_time BETWEEN ? AND ?) `
|
|
|
- // pars = append(pars, st, ed)
|
|
|
- // }else if req.TimeType == 3 && req.StartDate != "" && req.EndDate != "" {
|
|
|
- // st := fmt.Sprint(req.StartDate, " 00:00:00")
|
|
|
- // ed := fmt.Sprint(req.EndDate, " 23:59:59")
|
|
|
- // cond += ` AND (c.invoice_time BETWEEN ? AND ?) AND (d.invoice_time BETWEEN ? AND ?) `
|
|
|
- // pars = append(pars, st, ed, st, ed)
|
|
|
- // }
|
|
|
- //} else if req.StartDate != "" && req.EndDate != "" {
|
|
|
- // st := fmt.Sprint(req.StartDate, " 00:00:00")
|
|
|
- // ed := fmt.Sprint(req.EndDate, " 23:59:59")
|
|
|
- // cond += ` AND ((c.invoice_time BETWEEN ? AND ?) or (d.invoice_time BETWEEN ? AND ?))`
|
|
|
- // pars = append(pars, st, ed, st, ed)
|
|
|
- //}
|
|
|
-
|
|
|
- //if req.HasInvoice == "1" {
|
|
|
- // cond += ` AND a.invoice_id > 0 `
|
|
|
- //}else if req.HasInvoice == "0" {
|
|
|
- // cond += ` AND a.invoice_id = 0 `
|
|
|
- //}
|
|
|
- //
|
|
|
- //if req.HasPayment == "1" {
|
|
|
- // cond += ` AND a.payment_id > 0 `
|
|
|
- //}else if req.HasPayment == "0" {
|
|
|
- // cond += ` AND a.payment_id = 0 `
|
|
|
- //}
|
|
|
-
|
|
|
- page := new(base.Page)
|
|
|
- page.SetPageSize(req.PageSize)
|
|
|
- page.SetCurrent(req.Current)
|
|
|
- //排序
|
|
|
- if req.SortType == "" {
|
|
|
- req.SortType = "asc"
|
|
|
- }
|
|
|
- if req.SortType != "desc" && req.SortType != "asc" {
|
|
|
- resp.Fail("排序类型不正确", c)
|
|
|
- return
|
|
|
- }
|
|
|
- if req.SortParam == "" {
|
|
|
- page.AddOrderItem(base.OrderItem{Column: "e.start_date", Asc: true})
|
|
|
- } else if req.SortParam == "start_date" {
|
|
|
- if req.SortType == "asc" {
|
|
|
- page.AddOrderItem(base.OrderItem{Column: "e.start_date", Asc: true})
|
|
|
- } else {
|
|
|
- page.AddOrderItem(base.OrderItem{Column: "e.start_date", Asc: false})
|
|
|
- }
|
|
|
- } else if req.SortParam == "end_date" {
|
|
|
- if req.SortType == "asc" {
|
|
|
- page.AddOrderItem(base.OrderItem{Column: "e.end_date", Asc: true})
|
|
|
- } else {
|
|
|
- page.AddOrderItem(base.OrderItem{Column: "e.end_date", Asc: false})
|
|
|
- }
|
|
|
- } else {
|
|
|
- resp.Fail("排序字段不正确", c)
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- if req.IsExport == 1 {
|
|
|
- page.SetPageSize(10000)
|
|
|
- page.SetCurrent(1)
|
|
|
- }
|
|
|
-
|
|
|
- cond += ` AND b.payment_amount > b.invoiced_amount AND b.contract_amount <> b.invoiced_amount `
|
|
|
- registerList, total, e := fms.GetInvoiceCensusPageList(page, cond, pars)
|
|
|
- if e != nil {
|
|
|
- resp.FailMsg("获取失败", "获取商品到款统计列表总数失败, Err: "+e.Error(), c)
|
|
|
- return
|
|
|
- }
|
|
|
- queryRegisterIds := make([]int, 0)
|
|
|
- for _, v := range registerList {
|
|
|
- queryRegisterIds = append(queryRegisterIds, v.ContractRegisterId)
|
|
|
- }
|
|
|
- //fmt.Println("queryRegisterIds:",queryRegisterIds)
|
|
|
- results := new(fms.NotInvoicePaymentCensusResp)
|
|
|
- if len(queryRegisterIds) > 0 {
|
|
|
- // 获取合同的套餐金额信息
|
|
|
- serviceAmountList, e := fms.GetContractServiceAmountByContractRegisterIds(queryRegisterIds)
|
|
|
- if e != nil {
|
|
|
- resp.FailData("获取合同的套餐金额信息失败", "Err:"+e.Error(), c)
|
|
|
- return
|
|
|
- }
|
|
|
- serviceAmountMap := make(map[int]map[int]*fms.ContractServiceAmount, 0)
|
|
|
- for _, v := range serviceAmountList {
|
|
|
- if _, ok := serviceAmountMap[v.ContractRegisterId]; !ok {
|
|
|
- serviceAmountMap[v.ContractRegisterId] = make(map[int]*fms.ContractServiceAmount)
|
|
|
- }
|
|
|
- serviceAmountMap[v.ContractRegisterId][v.ProductId] = v
|
|
|
- }
|
|
|
-
|
|
|
- // 获取汇总数据IDs, 用于查询合计数据
|
|
|
- summaryIdsCond := cond
|
|
|
- summaryIdsPars := pars
|
|
|
- if req.SellerIds != "" {
|
|
|
- sellerIds := strings.Split(req.SellerIds, ",")
|
|
|
- summaryIdsCond += ` AND c.seller_id in ? AND a.payment_id <> 0 AND (d.origin_amount > c.origin_amount OR c.origin_amount IS NULL) `
|
|
|
- summaryIdsPars = append(summaryIdsPars, sellerIds)
|
|
|
- } else {
|
|
|
- summaryIdsCond += ` AND a.payment_id <> 0 AND (d.origin_amount > c.origin_amount OR c.origin_amount IS NULL) `
|
|
|
- summaryIdsPars = append(summaryIdsPars)
|
|
|
- }
|
|
|
- summaryIds, e := fms.GetInvoicePaymentCensusSummaryDataIds(summaryIdsCond, summaryIdsPars)
|
|
|
- if e != nil {
|
|
|
- resp.FailMsg("获取失败", "获取商品到款汇总IDs失败, Err: "+e.Error(), c)
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- //fmt.Println("summaryIds:",summaryIds)
|
|
|
- var listErr, totalErr, totalGroupErr error
|
|
|
- wg := sync.WaitGroup{}
|
|
|
-
|
|
|
- // 响应列表
|
|
|
- respList := make([]*fms.NotPaymentCensusItem, 0)
|
|
|
- summaryList := make([]*fms.NotInvoicePaymentSummaryItem, 0)
|
|
|
- wg.Add(1)
|
|
|
- go func() {
|
|
|
- defer wg.Done()
|
|
|
-
|
|
|
- // 获取汇总数据
|
|
|
- summaryCond := cond
|
|
|
- summaryCond += ` AND a.register_id IN ?`
|
|
|
- summaryPars := pars
|
|
|
- summaryPars = append(summaryPars, queryRegisterIds)
|
|
|
- //if req.SellerIds != "" {
|
|
|
- // sellerIds := strings.Split(req.SellerIds, ",")
|
|
|
- // summaryCond += ` AND c.seller_id in ? AND a.payment_id <> 0 AND (d.origin_amount > c.origin_amount OR c.origin_amount IS NULL) `
|
|
|
- // summaryPars = append(summaryPars, sellerIds, sellerIds)
|
|
|
- //} else {
|
|
|
- // summaryCond += ` AND a.payment_id <> 0 AND (d.origin_amount > c.origin_amount OR c.origin_amount IS NULL) `
|
|
|
- // summaryPars = append(summaryPars)
|
|
|
- //}
|
|
|
-
|
|
|
- summaryData, e := fms.GetNotInvoicePaymentCensusSummaryData(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)
|
|
|
- //}
|
|
|
- NotInvoiceSummaryMap := make(map[int][]*fms.NotInvoicePaymentSummaryItem, 0)
|
|
|
- for _, v := range summaryList {
|
|
|
- NotInvoiceSummaryMap[v.RegisterId] = append(NotInvoiceSummaryMap[v.RegisterId], v)
|
|
|
- }
|
|
|
-
|
|
|
- // 重组汇总数据
|
|
|
- summaryMap := make(map[int][]*fms.NotPaymentCensusInfo)
|
|
|
- sellerList, e := crmService.GetSellerDepartmentListWithGroupAndTeam()
|
|
|
- if e != nil {
|
|
|
- resp.FailData("获取销售失败", "Err:"+e.Error(), c)
|
|
|
- return
|
|
|
- }
|
|
|
- sellerMap := make(map[int]*crm.SellerAdminWithGroupTeam)
|
|
|
- for i := range sellerList {
|
|
|
- sellerMap[sellerList[i].SellerId] = sellerList[i]
|
|
|
- }
|
|
|
- sellerTypeMap := map[int]string{2: "FICC销售", 5: "权益销售"}
|
|
|
- // 货币列表
|
|
|
- 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)
|
|
|
- for i := range currencyList {
|
|
|
- unitMap[currencyList[i].Code] = currencyList[i].UnitName
|
|
|
- }
|
|
|
-
|
|
|
- for registerId, list := range NotInvoiceSummaryMap {
|
|
|
- for _, v := range list {
|
|
|
- v.NotInvoicedAmountTotal = serviceAmountMap[registerId][v.ServiceProductId].ServiceAmount - v.InvoiceAmountTotal
|
|
|
-
|
|
|
- if v.SellerId > 0 && v.RaiSellerId > 0 {
|
|
|
- if v.ServiceProductId == 1 {
|
|
|
- v.SellerGroupId = sellerMap[v.SellerId].GroupId
|
|
|
- v.SellerGroupName = sellerMap[v.SellerId].GroupName
|
|
|
- v.SellerType = sellerTypeMap[sellerMap[v.SellerId].DepartmentId]
|
|
|
- } else {
|
|
|
- v.RaiSellerGroupId = sellerMap[v.RaiSellerId].GroupId
|
|
|
- v.RaiSellerGroupName = sellerMap[v.RaiSellerId].GroupName
|
|
|
- v.SellerType = sellerTypeMap[sellerMap[v.RaiSellerId].DepartmentId]
|
|
|
- }
|
|
|
- } else if v.SellerId > 0 && v.RaiSellerId == 0{
|
|
|
- v.SellerGroupId = sellerMap[v.SellerId].GroupId
|
|
|
- v.SellerGroupName = sellerMap[v.SellerId].GroupName
|
|
|
- v.SellerType = sellerTypeMap[sellerMap[v.SellerId].DepartmentId]
|
|
|
- }else if v.SellerId == 0 && v.RaiSellerId > 0 {
|
|
|
- v.RaiSellerGroupId = sellerMap[v.RaiSellerId].GroupId
|
|
|
- v.RaiSellerGroupName = sellerMap[v.RaiSellerId].GroupName
|
|
|
- v.SellerType = sellerTypeMap[sellerMap[v.RaiSellerId].DepartmentId]
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 响应列表
|
|
|
- for i := range registerList {
|
|
|
- v := new(fms.NotPaymentCensusItem)
|
|
|
- v.SummaryId = registerList[i].SummaryId
|
|
|
- v.ContractRegisterId = registerList[i].ContractRegisterId
|
|
|
- v.CompanyName = registerList[i].CompanyName
|
|
|
- v.NewCompany = registerList[i].NewCompany
|
|
|
- v.StartDate = utils.TimeTransferString(utils.FormatDate, registerList[i].StartDate)
|
|
|
- v.EndDate = utils.TimeTransferString(utils.FormatDate, registerList[i].EndDate)
|
|
|
- v.InvoicePaymentList = summaryMap[registerList[i].SummaryId]
|
|
|
- v.ContractType = registerList[i].ContractType
|
|
|
- v.ContractCode = registerList[i].ContractCode
|
|
|
- v.ContractAmount = registerList[i].ContractAmount
|
|
|
- v.UnitName = unitMap[registerList[i].CurrencyUnit]
|
|
|
- v.ProductIds = registerList[i].ProductIds
|
|
|
- if registerList[i].InvoicedAmount != 0 {
|
|
|
- v.NotInvoiceTotal = registerList[i].ContractAmount - registerList[i].InvoicedAmount
|
|
|
- } else {
|
|
|
- v.NotInvoiceTotal = registerList[i].ContractAmount - registerList[i].PaymentAmount
|
|
|
- }
|
|
|
-
|
|
|
- v.NotInvoiceList = NotInvoiceSummaryMap[summaryList[i].RegisterId]
|
|
|
- respList = append(respList, v)
|
|
|
- }
|
|
|
- }()
|
|
|
-
|
|
|
- // 开票到款金额合计(换算后)
|
|
|
- var invoiceTotal, paymentTotal, contractAmount float64
|
|
|
- wg.Add(1)
|
|
|
- go func() {
|
|
|
- defer wg.Done()
|
|
|
-
|
|
|
- if len(summaryIds) == 0 {
|
|
|
- return
|
|
|
- }
|
|
|
- amountTotalCond := `a.id IN ?`
|
|
|
- amountTotalPars := make([]interface{}, 0)
|
|
|
- amountTotalPars = append(amountTotalPars, summaryIds)
|
|
|
- invoiceSum, e := fms.GetContractSummaryInvoicePaymentAmountTotal(amountTotalCond, amountTotalPars, 1)
|
|
|
- if e != nil {
|
|
|
- totalErr = fmt.Errorf("获取汇总开票金额合计失败, Err: %s", e.Error())
|
|
|
- return
|
|
|
- }
|
|
|
- invoiceTotal, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", invoiceSum), 64)
|
|
|
- paymentSum, e := fms.GetContractSummaryInvoicePaymentAmountTotal(amountTotalCond, amountTotalPars, 2)
|
|
|
- if e != nil {
|
|
|
- totalErr = fmt.Errorf("获取汇总到款金额合计失败, Err: %s", e.Error())
|
|
|
- return
|
|
|
- }
|
|
|
- paymentTotal, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", paymentSum), 64)
|
|
|
- }()
|
|
|
-
|
|
|
- // 分币种金额统计
|
|
|
- invoiceCurrencyTotals := make([]*fms.InvoiceListCurrencyTotal, 0)
|
|
|
- paymentCurrencyTotals := make([]*fms.InvoiceListCurrencyTotal, 0)
|
|
|
- contractAmountCurrencyTotals := make([]*fms.InvoiceListCurrencyTotal, 0)
|
|
|
- wg.Add(1)
|
|
|
- go func() {
|
|
|
- defer wg.Done()
|
|
|
-
|
|
|
- currencyOB := new(fms.CurrencyUnit)
|
|
|
- currencyCond := `enable = 1`
|
|
|
- currencyPars := make([]interface{}, 0)
|
|
|
- currencyList, e := currencyOB.List(currencyCond, currencyPars)
|
|
|
- if e != nil {
|
|
|
- totalGroupErr = fmt.Errorf("获取货币列表失败, Err: %s", e.Error())
|
|
|
- return
|
|
|
- }
|
|
|
- unitMap := make(map[string]string)
|
|
|
- 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,
|
|
|
- })
|
|
|
- contractAmountCurrencyTotals = append(contractAmountCurrencyTotals, &fms.InvoiceListCurrencyTotal{
|
|
|
- Name: currencyList[i].Name,
|
|
|
- UnitName: currencyList[i].UnitName,
|
|
|
- Code: currencyList[i].Code,
|
|
|
- FlagImg: currencyList[i].FlagImg,
|
|
|
- })
|
|
|
- }
|
|
|
-
|
|
|
- if len(summaryIds) == 0 {
|
|
|
- return
|
|
|
- }
|
|
|
- totalGroupCond := `a.id IN ?`
|
|
|
- totalGroupPars := make([]interface{}, 0)
|
|
|
- totalGroupPars = append(totalGroupPars, summaryIds)
|
|
|
- invoiceSumGroup, e := fms.GetSummaryListCurrencySum(totalGroupCond, totalGroupPars, 1)
|
|
|
- if e != nil {
|
|
|
- totalGroupErr = fmt.Errorf("获取汇总货币合计开票金额失败, Err: %s", e.Error())
|
|
|
- return
|
|
|
- }
|
|
|
- paymentSumGroup, e := fms.GetSummaryListCurrencySum(totalGroupCond, totalGroupPars, 2)
|
|
|
- if e != nil {
|
|
|
- totalGroupErr = fmt.Errorf("获取汇总货币合计到款金额失败, Err: %s", e.Error())
|
|
|
- return
|
|
|
- }
|
|
|
- invoiceSumMap := make(map[string]float64)
|
|
|
- paymentSumMap := make(map[string]float64)
|
|
|
- contractSumMap := make(map[string]float64)
|
|
|
-
|
|
|
- for i := range invoiceSumGroup {
|
|
|
- invoiceSumMap[invoiceSumGroup[i].CurrencyUnit] = invoiceSumGroup[i].OriginAmountTotal
|
|
|
- continue
|
|
|
- }
|
|
|
- for i := range paymentSumGroup {
|
|
|
- paymentSumMap[paymentSumGroup[i].CurrencyUnit] = paymentSumGroup[i].OriginAmountTotal
|
|
|
- continue
|
|
|
- }
|
|
|
- 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
|
|
|
- }
|
|
|
-
|
|
|
- contractRegisters, err := fms.GetContractInfoByRegisterIds(queryRegisterIds)
|
|
|
- if err != nil {
|
|
|
- resp.FailMsg("查询合同信息失败", "查询合同信息失败, Err: "+err.Error(), c)
|
|
|
- return
|
|
|
- }
|
|
|
- for _, v := range contractRegisters {
|
|
|
- if v.RMBRate == 0.0 {
|
|
|
- v.RMBRate = 1
|
|
|
- }
|
|
|
- amount, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", v.ContractAmount/v.RMBRate), 64)
|
|
|
- contractAmount += amount
|
|
|
- contractSumMap[v.CurrencyUnit] = v.ContractAmount
|
|
|
- }
|
|
|
- for _, v := range contractAmountCurrencyTotals {
|
|
|
- v.Amount = contractSumMap[v.Code] - invoiceSumMap[v.Code]
|
|
|
- }
|
|
|
-
|
|
|
- }()
|
|
|
-
|
|
|
- wg.Wait()
|
|
|
-
|
|
|
- if listErr != nil {
|
|
|
- resp.FailMsg("获取失败", listErr.Error(), c)
|
|
|
- return
|
|
|
- }
|
|
|
- if totalErr != nil {
|
|
|
- resp.FailMsg("获取失败", totalErr.Error(), c)
|
|
|
- return
|
|
|
- }
|
|
|
- if totalGroupErr != nil {
|
|
|
- resp.FailMsg("获取失败", totalGroupErr.Error(), c)
|
|
|
- return
|
|
|
- }
|
|
|
- results.DataList = respList
|
|
|
- results.InvoiceTotal = invoiceTotal
|
|
|
- results.PaymentTotal = paymentTotal
|
|
|
- results.NotInvoiceTotal = contractAmount - invoiceTotal
|
|
|
- results.InvoiceCurrencyTotal = invoiceCurrencyTotals
|
|
|
- results.PaymentCurrencyTotal = paymentCurrencyTotals
|
|
|
- results.NotInvoiceCurrencyTotal = contractAmountCurrencyTotals
|
|
|
- }
|
|
|
-
|
|
|
- // 是否导出
|
|
|
- if req.IsExport == 1 {
|
|
|
- ExportNotInvoiceCensusList(c, results)
|
|
|
- return
|
|
|
- }
|
|
|
- page.SetTotal(total)
|
|
|
- baseData := new(base.BaseData)
|
|
|
- baseData.SetPage(page)
|
|
|
- baseData.SetList(results)
|
|
|
- resp.OkData("获取成功", baseData, c)
|
|
|
-}
|