ziwen 1 year ago
parent
commit
0f4e7c7468
2 changed files with 32 additions and 12 deletions
  1. 23 4
      controller/census/invoice_payment.go
  2. 9 8
      models/fms/invoice_payment_summary.go

+ 23 - 4
controller/census/invoice_payment.go

@@ -2140,6 +2140,7 @@ func (ct *InvoicePaymentController) NotPaymentList(c *gin.Context) {
 	for i := range registerList {
 		queryRegisterIds = append(queryRegisterIds, registerList[i].ContractRegisterId)
 	}
+	fmt.Println("queryRegisterIds:",queryRegisterIds)
 
 	//fmt.Println("queryRegisterIds:",queryRegisterIds)
 	results := new(fms.NotInvoicePaymentCensusResp)
@@ -3064,7 +3065,7 @@ func (ct *InvoicePaymentController) NotInvoiceList2(c *gin.Context) {
 			for i := range sellerList {
 				sellerMap[sellerList[i].SellerId] = sellerList[i]
 			}
-
+			sellerTypeMap := map[int]string{2: "FICC销售", 5: "权益销售"}
 			// 货币列表
 			currencyOB := new(fms.CurrencyUnit)
 			currencyCond := `enable = 1`
@@ -3082,12 +3083,25 @@ func (ct *InvoicePaymentController) NotInvoiceList2(c *gin.Context) {
 			for registerId, list := range NotInvoiceSummaryMap {
 				for _, v := range list {
 					v.NotInvoicedAmountTotal = serviceAmountMap[registerId][v.ServiceProductId].ServiceAmount - v.InvoiceAmountTotal
-					if v.ServiceProductId == 1 {
+
+					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
-					} else {
+						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]
 					}
 				}
 			}
@@ -3107,7 +3121,12 @@ func (ct *InvoicePaymentController) NotInvoiceList2(c *gin.Context) {
 				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)
 			}

+ 9 - 8
models/fms/invoice_payment_summary.go

@@ -191,11 +191,11 @@ func GetInvoicePaymentSummaryByRegisterIdAndInvoiceId(registerId, invocieId int)
 }
 
 type IncomeSummaryItem struct {
-	CompanyName string    `json:"company_name" description:"客户名称"`
-	ContractType  int       `json:"contract_type" description:"是否为新客户: 2-否; 1-是"`
-	InvoiceDate time.Time `json:"invoice_time" description:"开票日期"`
-	Amount      float64   `json:"amount" description:"金额"`
-	SellerName  string    `json:"seller_name" description:"销售名称"`
+	CompanyName  string    `json:"company_name" description:"客户名称"`
+	ContractType int       `json:"contract_type" description:"是否为新客户: 2-否; 1-是"`
+	InvoiceDate  time.Time `json:"invoice_time" description:"开票日期"`
+	Amount       float64   `json:"amount" description:"金额"`
+	SellerName   string    `json:"seller_name" description:"销售名称"`
 }
 
 // GetContractSummaryIncomeAmount 获取汇总金额合计信息
@@ -246,14 +246,14 @@ func GetInvoiceCensusPageList(page base.IPage, condition string, pars []interfac
 func GetNoPaymentCensusPageList(page base.IPage, condition string, pars []interface{}) (results []*InvoiceSummary, count int64, err error) {
 	query := global.DEFAULT_MYSQL.Table("invoice_payment_summary AS a").
 		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 "+
-			" ,c.invoice_time ").
+			" ,c.invoice_time ","c.origin_amount AS summary_invoice_amount","d.origin_amount AS summary_payment_amount","a.invoice_id","a.payment_id").
 		Joins("JOIN contract_register AS b 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")
+		Where(condition, pars...).Group("id")
 
 	nq := global.DEFAULT_MYSQL.Table("(?) AS e", query).
-		Select("*")
+		Select("*").Where(" e.invoiced_amount_count <> 0 AND e.invoice_id <> 0 AND ( e.summary_invoice_amount > e.summary_payment_amount OR e.summary_payment_amount IS NULL ) ")
 	nq.Count(&count)
 	if len(page.GetOrderItemsString()) > 0 {
 		nq = nq.Order(page.GetOrderItemsString())
@@ -315,6 +315,7 @@ type NotInvoicePaymentSummaryItem struct {
 	PaymentAmountTotal     float64   `gorm:"column:payment_amount_total" json:"payment_amount_total" description:"合同金额"`
 	InvoiceAmountTotal     float64   `gorm:"column:invoice_amount_total" json:"invoice_amount_total" description:"开票金额"`
 	NotInvoicedAmountTotal float64   ` json:"not_invoiced_amount_total" description:"未开票金额"`
+	SellerType             string    `json:"seller_type" description:"销售类型"`
 	ContractRegister
 }