Browse Source

Merge branch 'pool_345' into fms_2.5

# Conflicts:
#	controller/contract/register.go
#	models/fms/contract_invoice.go
ziwen 2 years ago
parent
commit
7fe83792b8
2 changed files with 32 additions and 28 deletions
  1. 14 19
      controller/contract/register.go
  2. 18 9
      models/fms/contract_invoice.go

+ 14 - 19
controller/contract/register.go

@@ -1934,7 +1934,7 @@ func (rg *RegisterController) Export(c *gin.Context) {
 // @Title 开票/到款列表
 // @Description 开票/到款列表
 // @Param   InvoiceType		query	int		false	"类型: 1-开票登记; 2-到款登记"
-// @Param   ContractCode	query	string	false	"合同编号"
+// @Param   Keyword			query	string	false	"查询关键字"
 // @Param   StartDate		query	string	false	"开始日期"
 // @Param   EndDate			query	string	false	"结束日期"
 // @Param   MinAmount		query	float64	false	"开票金额区间-最小值"
@@ -1965,44 +1965,38 @@ func (rg *RegisterController) InvoiceList(c *gin.Context) {
 	cond := `invoice_type = ?`
 	pars := make([]interface{}, 0)
 	pars = append(pars, req.InvoiceType)
-	// 合同编号
-	if req.ContractCode != "" {
-		kw := fmt.Sprint("%", req.ContractCode, "%")
-		pars = append(pars, kw)
-		// 开票列表同时模糊查询销售名称
-		if req.InvoiceType == fms.ContractInvoiceTypeMake {
-			cond += ` AND (contract_code LIKE ? )`
-			pars = append(pars, kw)
-		} else {
-			cond += ` AND contract_code LIKE ?`
-			pars = append(pars, kw)
-		}
+	// 搜索
+	if req.Keyword != "" {
+		kw := fmt.Sprint("%", req.Keyword, "%")
+		//pars = append(pars, kw)
+		cond += `  AND (b.company_name LIKE ? OR a.contract_code LIKE ?)`
+		pars = append(pars, kw, kw)
 	}
 	if req.StartDate != "" && req.EndDate != "" {
 		st := fmt.Sprint(req.StartDate, " 00:00:00")
 		ed := fmt.Sprint(req.EndDate, " 23:59:59")
-		cond += ` AND (invoice_time BETWEEN ? AND ?)`
+		cond += ` AND (a.invoice_time BETWEEN ? AND ?)`
 		pars = append(pars, st, ed)
 	}
 	if req.MinAmount > 0 {
-		cond += ` AND amount >= ?`
+		cond += ` AND a.amount >= ?`
 		pars = append(pars, req.MinAmount)
 	}
 	if req.MaxAmount > 0 {
-		cond += ` AND amount <= ?`
+		cond += ` AND a.amount <= ?`
 		pars = append(pars, req.MaxAmount)
 	}
 
 	// 套餐类型
 	if req.ServiceProductId > 0 {
-		cond += ` AND service_product_id = ?`
+		cond += ` AND a.service_product_id = ?`
 		pars = append(pars, req.ServiceProductId)
 	}
 
 	// 销售
 	if req.SellerIds != "" {
 		sellerIds := strings.Split(req.SellerIds, ",")
-		cond += ` AND (seller_id in (?))`
+		cond += ` AND (a.seller_id in (?))`
 		pars = append(pars, sellerIds)
 	}
 
@@ -2148,7 +2142,7 @@ func ExportInvoiceList(c *gin.Context, req fms.ContractInvoiceListReq, results *
 	sheet.AddRow()
 
 	// 列表数据表头
-	titles := []string{"合同编号", "套餐类型", fmt.Sprintf("%s金额", listName), "金额单位", "换算金额(元)",
+	titles := []string{"客户名称", "合同编号", "套餐类型", fmt.Sprintf("%s金额", listName), "金额单位", "换算金额(元)",
 		fmt.Sprintf("%s日期", listName), "备注"}
 	titleRow := sheet.AddRow()
 	titleRow.SetHeight(40)
@@ -2165,6 +2159,7 @@ func ExportInvoiceList(c *gin.Context, req fms.ContractInvoiceListReq, results *
 	for _, v := range list {
 		dataRow := sheet.AddRow()
 		dataRow.SetHeight(20)
+		dataRow.AddCell().SetString(v.CompanyName)                             // 客户名称
 		dataRow.AddCell().SetString(v.ContractCode)                            // 合同编号
 		dataRow.AddCell().SetString(ServiceTemplateStrMap[v.ServiceProductId]) // 套餐类型
 		dataRow.AddCell().SetString(fmt.Sprint(v.OriginAmount))                // 开票金额

+ 18 - 9
models/fms/contract_invoice.go

@@ -16,7 +16,7 @@ type ContractInvoice struct {
 	Amount             float64   `gorm:"column:amount" json:"amount" description:"换算后的金额(人民币)"`
 	OriginAmount       float64   `gorm:"column:origin_amount" json:"origin_amount" description:"开票/到款金额"`
 	CurrencyUnit       string    `gorm:"column:currency_unit" json:"currency_unit" description:"货币国际代码"`
-	InvoiceType        int       `gorm:"column:invoice_type" json:"invoice_type" description:"类型: 1-开票登记; 2-到款登记;3-开票预登记;4-到款预登记"`
+	InvoiceType        int       `gorm:"column:invoice_type" json:"invoice_type" description:"类型: 1-开票登记; 2-到款登记"`
 	InvoiceDate        time.Time `gorm:"column:invoice_time" json:"invoice_time" description:"开票日期/到款月"`
 	SellerId           int       `gorm:"column:seller_id" json:"seller_id" description:"销售ID"`
 	SellerName         string    `gorm:"column:seller_name" json:"seller_name" description:"销售名称"`
@@ -62,6 +62,7 @@ type ContractInvoiceItem struct {
 	StartDate          string  `gorm:"column:start_date" json:"start_date" description:"约定开始时间"`
 	EndDate            string  `gorm:"column:end_date" json:"end_date" description:"约定结束时间"`
 	CreateTime         string  `gorm:"column:create_time" json:"create_time" description:"创建时间"`
+	CompanyName        string  `gorm:"column:company_name" json:"company_name" description:"客户名称"`
 }
 
 func (c *ContractInvoice) Create() (err error) {
@@ -221,7 +222,7 @@ func formatContractInvoice2ItemList(list []*ContractInvoice) (itemList []*Contra
 type ContractInvoiceListReq struct {
 	InvoiceType      int     `json:"invoice_type" form:"invoice_type" binding:"oneof=1 2" description:"类型: 1-开票登记; 2-到款登记"`
 	SellerIds        string  `json:"seller_ids" form:"seller_ids" description:"销售ID, 多个id用逗号拼接"`
-	ContractCode     string  `json:"contract_code" form:"contract_code" binding:"omitempty" description:"合同编号"`
+	Keyword          string  `json:"keyword" form:"keyword" binding:"omitempty" description:"搜索关键字"`
 	StartDate        string  `json:"start_date" form:"start_date" binding:"omitempty,datetime=2006-01-02" description:"开始日期"`
 	EndDate          string  `json:"end_date" form:"end_date" binding:"omitempty,datetime=2006-01-02" description:"结束日期"`
 	MinAmount        float64 `json:"min_amount" form:"min_amount" description:"开票金额区间-最小值"`
@@ -233,9 +234,11 @@ type ContractInvoiceListReq struct {
 
 // GetContractInvoiceItemPageList 获取合同开票/到款列表-分页
 func GetContractInvoiceItemPageList(page base.IPage, condition string, pars []interface{}) (count int64, results []*ContractInvoiceItem, err error) {
-	list := make([]*ContractInvoice, 0)
-	query := global.DEFAULT_MYSQL.Table("contract_invoice").
-		Where("is_deleted = 0").
+	list := make([]*ContractInvoiceRespItem, 0)
+	query := global.DEFAULT_MYSQL.Table("contract_invoice AS a").
+		Select("a.*, b.company_name").
+		Joins("JOIN contract_register b ON a.contract_register_id = b.contract_register_id").
+		Where("a.is_deleted = 0").
 		Where(condition, pars...)
 	query.Count(&count)
 	if len(page.GetOrderItemsString()) > 0 {
@@ -252,7 +255,7 @@ func GetContractInvoiceItemPageList(page base.IPage, condition string, pars []in
 }
 
 // formatContractInvoice2Item 格式化ContractInvoiceItem
-func formatContractInvoice2Item(item *ContractInvoice) (formatItem *ContractInvoiceItem) {
+func formatContractInvoice2Item(item *ContractInvoiceRespItem) (formatItem *ContractInvoiceItem) {
 	formatItem = new(ContractInvoiceItem)
 	formatItem.ContractInvoiceId = item.ContractInvoiceId
 	formatItem.ContractRegisterId = item.ContractRegisterId
@@ -269,6 +272,7 @@ func formatContractInvoice2Item(item *ContractInvoice) (formatItem *ContractInvo
 	formatItem.IsPrePay = item.IsPrePay
 	formatItem.ServiceProductId = item.ServiceProductId
 	formatItem.CreateTime = utils.TimeTransferString(utils.FormatDateTime, item.CreateTime)
+	formatItem.CompanyName = item.CompanyName
 	return
 }
 
@@ -501,9 +505,9 @@ type InvoiceListCurrencySum struct {
 
 // GetInvoiceListCurrencySum 获取开票/到款分货币合计
 func GetInvoiceListCurrencySum(condition string, pars []interface{}, groupRule string) (results []*InvoiceListCurrencySum, err error) {
-	query := global.DEFAULT_MYSQL.Table("contract_invoice").
-		Select("currency_unit, invoice_type, SUM(amount) AS amount_total, SUM(origin_amount) AS origin_amount_total").
-		Where("is_deleted = 0").
+	query := global.DEFAULT_MYSQL.Table("contract_invoice AS a").
+		Select("a.currency_unit, a.invoice_type, SUM(a.amount) AS amount_total, SUM(a.origin_amount) AS origin_amount_total, b.company_name").
+		Joins("JOIN contract_register b ON a.contract_register_id = b.contract_register_id").
 		Where(condition, pars...).
 		Group(groupRule)
 	err = query.Find(&results).Error
@@ -580,3 +584,8 @@ func formatContractInvoice2DetailItemList(list []*ContractInvoice) (itemList []*
 	}
 	return
 }
+
+type ContractInvoiceRespItem struct {
+	ContractInvoice
+	CompanyName string `gorm:"column:company_name" json:"company_name" description:"客户名称"`
+}