ziwen 1 năm trước cách đây
mục cha
commit
0baaac7b60
2 tập tin đã thay đổi với 106 bổ sung15 xóa
  1. 93 11
      controller/census/invoice_payment.go
  2. 13 4
      models/fms/invoice_payment_summary.go

+ 93 - 11
controller/census/invoice_payment.go

@@ -1548,16 +1548,22 @@ func (ct *InvoicePaymentController) NotInvoiceList(c *gin.Context) {
 
 	cond := `1 = 1`
 	pars := make([]interface{}, 0)
+	noSummaryCond := `1 = 1`
+	noSummaryPars := 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)
+		noSummaryCond += ` AND (b.company_name LIKE ? OR b.contract_code LIKE ?)`
+		noSummaryPars = append(noSummaryPars, kw, kw)
 	}
 	if req.SellerIds != "" {
 		sellerIds := strings.Split(req.SellerIds, ",")
 		cond += ` AND (c.seller_id in ?)`
 		pars = append(pars, sellerIds)
+		noSummaryCond += ` AND (b.seller_id in ? OR b.rai_seller_id in ?)`
+		noSummaryPars = append(noSummaryPars, sellerIds, sellerIds)
 	}
 	// 套餐筛选
 	if req.ServiceTypes != "" {
@@ -1570,15 +1576,20 @@ func (ct *InvoicePaymentController) NotInvoiceList(c *gin.Context) {
 		if len(tempRegisterIds) > 0 {
 			cond += ` AND a.register_id IN ?`
 			pars = append(pars, tempRegisterIds)
+			noSummaryCond += ` AND b.register_id IN ? `
+			noSummaryPars = append(noSummaryPars, tempRegisterIds)
 		} else {
 			cond += ` AND 1 = 2`
+			noSummaryCond += ` AND 1 = 2`
 		}
 	}
 
 	if req.ListParam == 1 {
 		cond += ` AND a.service_product_id = 1 `
+		noSummaryCond += ` AND b.product_ids = '1' `
 	} else if req.ListParam == 2 {
 		cond += ` AND a.service_product_id = 2 `
+		noSummaryCond += ` AND b.product_ids = '2' `
 	}
 
 	// 开票到款日期
@@ -1653,7 +1664,7 @@ func (ct *InvoicePaymentController) NotInvoiceList(c *gin.Context) {
 		page.SetCurrent(1)
 	}
 
-	cond += `  AND b.contract_amount <> b.invoiced_amount `
+	cond += `  AND b.contract_amount <> b.invoiced_amount AND b.is_deleted = 0 `
 	registerList, total, e := fms.GetInvoiceCensusPageList(page, cond, pars)
 	if e != nil {
 		resp.FailMsg("获取失败", "获取商品到款统计列表总数失败, Err: "+e.Error(), c)
@@ -1663,7 +1674,7 @@ func (ct *InvoicePaymentController) NotInvoiceList(c *gin.Context) {
 	for _, v := range registerList {
 		queryRegisterIds = append(queryRegisterIds, v.ContractRegisterId)
 	}
-	//fmt.Println("queryRegisterIds:",queryRegisterIds)
+	fmt.Println("queryRegisterIds:",queryRegisterIds)
 	results := new(fms.NotInvoicePaymentCensusResp)
 	if len(queryRegisterIds) > 0 {
 		// 获取合同的套餐金额信息
@@ -1678,7 +1689,7 @@ func (ct *InvoicePaymentController) NotInvoiceList(c *gin.Context) {
 				serviceAmountMap[v.ContractRegisterId] = make(map[int]*fms.ContractServiceAmount)
 			}
 			serviceAmountMap[v.ContractRegisterId][v.ProductId] = v
-			fmt.Println("ServiceAmount,ProductId",v.ServiceAmount,v.ProductId)
+			fmt.Println("ServiceAmount,ProductId",v.ServiceAmount,v.ProductId,v.ContractRegisterId)
 		}
 
 		// 获取汇总数据IDs, 用于查询合计数据
@@ -1728,18 +1739,45 @@ func (ct *InvoicePaymentController) NotInvoiceList(c *gin.Context) {
 				resp.FailMsg("获取失败", "获取商品到款汇总列表失败, Err: "+e.Error(), c)
 				return
 			}
+			notQueryRegisterIds := make([]int, 0)
+			for _, v := range summaryData {
+				notQueryRegisterIds = append(notQueryRegisterIds, v.ContractRegisterId)
+			}
+
+			noSummaryCond += ` AND b.is_deleted = 0`
+			noSummaryCond += ` AND b.contract_register_id IN ? AND b.contract_register_id NOT IN ?`
+			noSummaryPars = append(noSummaryPars, queryRegisterIds, notQueryRegisterIds)
+			noSummaryData, e := fms.GetNoInvoicePaymentCensusData(noSummaryCond, noSummaryPars)
+			if e != nil {
+				resp.FailMsg("获取失败", "GetNoInvoicePaymentCensusData, Err: "+e.Error(), c)
+				return
+			}
+			fmt.Println("len(summaryData)",len(summaryData))
+			fmt.Println("len(noSummaryData)",len(noSummaryData))
 			summaryList = summaryData
+			NotInvoiceSummaryMap := make(map[int][]*fms.NotInvoicePaymentSummaryItem, 0)
+			for _, v := range summaryList {
+				fmt.Println("v2.ContractRegisterId",v.ContractRegisterId)
+				NotInvoiceSummaryMap[v.RegisterId] = append(NotInvoiceSummaryMap[v.RegisterId], v)
+			}
+
+			summaryList = append(summaryList, noSummaryData...)
+
 			//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)
-			}
+
+			fmt.Println("len(NotInvoiceSummaryMap):",len(NotInvoiceSummaryMap))
+
 			for _, v := range summaryList {
-				if v.ProductIds == "1,2" && len(NotInvoiceSummaryMap[v.RegisterId]) < 2 {
+				fmt.Println("ProductIds:",v.ProductIds)
+				fmt.Println("ContractRegisterId:",v.ContractRegisterId)
+				fmt.Println("ServiceProductId:",v.ServiceProductId)
+				fmt.Println("RegisterId:",v.RegisterId)
+				fmt.Println("len(NotInvoiceSummaryMap[v.RegisterId]):",len(NotInvoiceSummaryMap[v.ContractRegisterId]))
+				if (v.ProductIds == "1,2" || v.ProductIds == "2,1") && len(NotInvoiceSummaryMap[v.ContractRegisterId]) == 1 {
 					if v.ServiceProductId == 1 {
 						item := fms.NotInvoicePaymentSummaryItem{
 							NotInvoicedAmountTotal: serviceAmountMap[v.ContractRegisterId][2].ServiceAmount,
@@ -1750,7 +1788,7 @@ func (ct *InvoicePaymentController) NotInvoiceList(c *gin.Context) {
 						item.RaiSellerId = v.RaiSellerId
 						item.RaiSellerName = v.RaiSellerName
 
-						NotInvoiceSummaryMap[v.RegisterId] = append(NotInvoiceSummaryMap[v.RegisterId], &item)
+						NotInvoiceSummaryMap[v.ContractRegisterId] = append(NotInvoiceSummaryMap[v.ContractRegisterId], &item)
 					} else {
 
 						item := fms.NotInvoicePaymentSummaryItem{
@@ -1762,8 +1800,52 @@ func (ct *InvoicePaymentController) NotInvoiceList(c *gin.Context) {
 						item.RaiSellerId = v.RaiSellerId
 						item.RaiSellerName = v.RaiSellerName
 
-						NotInvoiceSummaryMap[v.RegisterId] = append(NotInvoiceSummaryMap[v.RegisterId], &item)
+						NotInvoiceSummaryMap[v.ContractRegisterId] = append(NotInvoiceSummaryMap[v.ContractRegisterId], &item)
+					}
+				} else if (v.ProductIds == "1,2" || v.ProductIds == "2,1") && len(NotInvoiceSummaryMap[v.ContractRegisterId]) == 0 {
+					item1 := fms.NotInvoicePaymentSummaryItem{
+						NotInvoicedAmountTotal: serviceAmountMap[v.ContractRegisterId][2].ServiceAmount,
+						ServiceProductId:       2,
+					}
+					item1.SellerId = v.SellerId
+					item1.SellerName = v.SellerName
+					item1.RaiSellerId = v.RaiSellerId
+					item1.RaiSellerName = v.RaiSellerName
+					NotInvoiceSummaryMap[v.ContractRegisterId] = append(NotInvoiceSummaryMap[v.ContractRegisterId], &item1)
+
+					item2 := fms.NotInvoicePaymentSummaryItem{
+						NotInvoicedAmountTotal: serviceAmountMap[v.ContractRegisterId][1].ServiceAmount,
+						ServiceProductId:       1,
+					}
+					item2.SellerId = v.SellerId
+					item2.SellerName = v.SellerName
+					item2.RaiSellerId = v.RaiSellerId
+					item2.RaiSellerName = v.RaiSellerName
+
+					NotInvoiceSummaryMap[v.ContractRegisterId] = append(NotInvoiceSummaryMap[v.ContractRegisterId], &item2)
+				} else if v.ProductIds == "1" && len(NotInvoiceSummaryMap[v.ContractRegisterId]) == 0 {
+					item1 := fms.NotInvoicePaymentSummaryItem{
+						NotInvoicedAmountTotal: serviceAmountMap[v.ContractRegisterId][1].ServiceAmount,
+						ServiceProductId:       1,
+					}
+					item1.SellerId = v.SellerId
+					item1.SellerName = v.SellerName
+					item1.RaiSellerId = v.RaiSellerId
+					item1.RaiSellerName = v.RaiSellerName
+
+					NotInvoiceSummaryMap[v.ContractRegisterId] = append(NotInvoiceSummaryMap[v.ContractRegisterId], &item1)
+
+				} else if v.ProductIds == "2" && len(NotInvoiceSummaryMap[v.ContractRegisterId]) == 0 {
+					item2 := fms.NotInvoicePaymentSummaryItem{
+						NotInvoicedAmountTotal: serviceAmountMap[v.ContractRegisterId][2].ServiceAmount,
+						ServiceProductId:       2,
 					}
+					item2.SellerId = v.SellerId
+					item2.SellerName = v.SellerName
+					item2.RaiSellerId = v.RaiSellerId
+					item2.RaiSellerName = v.RaiSellerName
+
+					NotInvoiceSummaryMap[v.ContractRegisterId] = append(NotInvoiceSummaryMap[v.ContractRegisterId], &item2)
 				}
 			}
 
@@ -1843,7 +1925,7 @@ func (ct *InvoicePaymentController) NotInvoiceList(c *gin.Context) {
 					v.NotInvoiceTotal = registerList[i].ContractAmount - registerList[i].PaymentAmount
 				}
 
-				v.NotInvoiceList = NotInvoiceSummaryMap[summaryList[i].RegisterId]
+				v.NotInvoiceList = NotInvoiceSummaryMap[registerList[i].ContractRegisterId]
 				respList = append(respList, v)
 			}
 		}()

+ 13 - 4
models/fms/invoice_payment_summary.go

@@ -222,9 +222,9 @@ type InvoiceSummary struct {
 
 // GetInvoiceCensusPageList 获取未开票统计列表-总数
 func GetInvoiceCensusPageList(page base.IPage, condition string, pars []interface{}) (results []*InvoiceSummary, count int64, err error) {
-	query := global.DEFAULT_MYSQL.Table("invoice_payment_summary AS a").
+	query := global.DEFAULT_MYSQL.Table("contract_register AS b").
 		Select("b.*, a.id as summary_id, IF(a.invoice_id >0, 1,0) as sort_invoice_id, IF(a.payment_id >0, 1,0) as sort_payment_id, COALESCE(SUM( c.amount ),0) AS invoiced_amount_count,COALESCE(SUM( d.amount ),0) AS payment_amount_count ").
-		Joins("JOIN contract_register AS b ON a.register_id = b.contract_register_id AND b.is_deleted = 0").
+		Joins("left JOIN invoice_payment_summary AS a ON a.register_id = b.contract_register_id AND b.is_deleted = 0").
 		Joins("LEFT JOIN contract_invoice AS c ON a.invoice_id = c.contract_invoice_id AND c.is_deleted = 0").
 		Joins("LEFT JOIN contract_invoice AS d ON a.payment_id = d.contract_invoice_id AND d.is_deleted = 0").
 		Where(condition, pars...).Group("contract_register_id")
@@ -325,12 +325,21 @@ func GetNotInvoicePaymentCensusSummaryData(condition string, pars []interface{})
 		"c.origin_amount AS invoice_amount", "c.invoice_time AS invoice_date", "d.origin_amount AS payment_amount", "d.invoice_time AS payment_date",
 		"d.pay_type", "COALESCE(SUM( c.origin_amount ),0) AS invoice_amount_total", "COALESCE(SUM( d.origin_amount ),0) AS payment_amount_total",
 	}
-	query := global.DEFAULT_MYSQL.Table("invoice_payment_summary AS a").
+	query := global.DEFAULT_MYSQL.Table("contract_register AS b").
 		Select(strings.Join(fields, ",")).
-		Joins("JOIN contract_register AS b ON a.register_id = b.contract_register_id AND b.is_deleted = 0").
+		Joins("left JOIN invoice_payment_summary AS a ON a.register_id = b.contract_register_id  AND b.is_deleted = 0").
 		Joins("LEFT JOIN contract_invoice AS c ON a.invoice_id = c.contract_invoice_id AND c.is_deleted = 0").
 		Joins("LEFT JOIN contract_invoice AS d ON a.payment_id = d.contract_invoice_id AND d.is_deleted = 0").
 		Where(condition, pars...).Group("a.register_id,service_product_id")
 	query.Find(&results)
 	return
 }
+
+// GetNoInvoicePaymentCensusData
+func GetNoInvoicePaymentCensusData(condition string, pars []interface{}) (results []*NotInvoicePaymentSummaryItem, err error) {
+	query := global.DEFAULT_MYSQL.Table("contract_register AS b").
+		Select("*").
+		Where(condition, pars...).Group("contract_register_id")
+	query.Find(&results)
+	return
+}