浏览代码

fix: 开票/到款列表金额合计

hsun 2 年之前
父节点
当前提交
c0bdabbcc7
共有 2 个文件被更改,包括 42 次插入9 次删除
  1. 30 8
      controller/contract/register.go
  2. 12 1
      models/fms/contract_invoice.go

+ 30 - 8
controller/contract/register.go

@@ -1217,6 +1217,14 @@ func (rg *RegisterController) InvoiceList(c *gin.Context) {
 		resp.FailData("参数解析失败", err.Translate(global.Trans), c)
 		return
 	}
+	pageSize := req.PageSize
+	pageIndex := req.Current
+	if pageSize <= 0 {
+		pageSize = utils.PageSize20
+	}
+	if pageIndex <= 0 {
+		pageIndex = 1
+	}
 
 	cond := `invoice_type = ?`
 	pars := make([]interface{}, 0)
@@ -1243,21 +1251,35 @@ func (rg *RegisterController) InvoiceList(c *gin.Context) {
 	}
 
 	page := new(base.Page)
-	page.SetPageSize(req.PageSize)
-	page.SetCurrent(req.Current)
+	page.SetPageSize(pageSize)
+	page.SetCurrent(pageIndex)
 	page.AddOrderItem(base.OrderItem{Column: "invoice_time", Asc: false})
-
 	total, list, e := fms.GetContractInvoiceItemPageList(page, cond, pars)
 	if e != nil {
 		resp.FailMsg("获取失败", "获取合同开票/到款列表失败, Err: "+e.Error(), c)
 		return
 	}
-
 	page.SetTotal(total)
-	baseData := new(base.BaseData)
-	baseData.SetPage(page)
-	baseData.SetList(list)
-	resp.OkData("获取成功", baseData, c)
+
+	// 金额合计
+	ob := new(fms.ContractInvoice)
+	amountTotal, e := ob.Sum("amount", cond, pars)
+	if e != nil {
+		resp.FailMsg("获取失败", "获取合同开票/到款列表合计金额失败, Err: "+e.Error(), c)
+		return
+	}
+
+	type RespData struct {
+		Page        *base.Page  `json:"page"`
+		List        interface{} `json:"list"`
+		AmountTotal float64     `json:"amount_total"`
+	}
+	respData := &RespData{
+		Page:        page,
+		List:        list,
+		AmountTotal: amountTotal,
+	}
+	resp.OkData("获取成功", respData, c)
 }
 
 // InvoiceExport

+ 12 - 1
models/fms/contract_invoice.go

@@ -53,6 +53,17 @@ func (c *ContractInvoice) Update(updateCols []string) (err error) {
 	return
 }
 
+func (c *ContractInvoice) Sum(field, condition string, pars []interface{}) (total float64, err error) {
+	totalList := make([]float64, 0)
+	err = global.DEFAULT_MYSQL.Model(c).
+		Where(condition, pars...).
+		Pluck(field, &totalList).Error
+	for i := range totalList {
+		total += totalList[i]
+	}
+	return
+}
+
 func (c *ContractInvoice) List(condition string, pars []interface{}, orderRule string) (list []*ContractInvoice, err error) {
 	list = make([]*ContractInvoice, 0)
 	query := global.DEFAULT_MYSQL.Model(c).
@@ -206,4 +217,4 @@ func DeleteContractInvoicesByRegisterId(registerId int) (err error) {
 	sql := `UPDATE contract_invoice SET is_deleted = 1 WHERE contract_register_id = ?`
 	err = global.DEFAULT_MYSQL.Exec(sql, registerId).Error
 	return
-}
+}