Browse Source

Merge branch 'master' into dev/2.1

hsun 2 years ago
parent
commit
c5d6478670
2 changed files with 41 additions and 13 deletions
  1. 40 13
      controller/contract/register.go
  2. 1 0
      models/fms/contract_invoice.go

+ 40 - 13
controller/contract/register.go

@@ -1278,6 +1278,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)
@@ -1304,21 +1312,36 @@ 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
+	}
+	amountTotal, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", amountTotal), 64)
+
+	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
@@ -1343,6 +1366,10 @@ func (rg *RegisterController) InvoiceExport(c *gin.Context) {
 		resp.FailData("参数解析失败", err.Translate(global.Trans), c)
 		return
 	}
+	listName := "开票"
+	if req.InvoiceType == fms.ContractInvoiceTypePay {
+		listName = "到款"
+	}
 
 	cond := `invoice_type = ?`
 	pars := make([]interface{}, 0)
@@ -1373,7 +1400,7 @@ func (rg *RegisterController) InvoiceExport(c *gin.Context) {
 	orderRule := `invoice_time DESC`
 	list, e := cr.List(cond, pars, orderRule)
 	if e != nil {
-		resp.FailData("获取开票/到款列表失败", "Err:"+e.Error(), c)
+		resp.FailData(fmt.Sprintf("获取%s列表失败", listName), "Err:"+e.Error(), c)
 		return
 	}
 	if len(list) == 0 {
@@ -1392,7 +1419,7 @@ func (rg *RegisterController) InvoiceExport(c *gin.Context) {
 	style.Alignment = alignment
 	style.ApplyAlignment = true
 
-	sheet, err := xlsxFile.AddSheet("开票列表")
+	sheet, err := xlsxFile.AddSheet(fmt.Sprintf("%s列表", listName))
 	if err != nil {
 		resp.FailData("新增Sheet失败", "Err:"+err.Error(), c)
 		return
@@ -1405,10 +1432,10 @@ func (rg *RegisterController) InvoiceExport(c *gin.Context) {
 	cell1.SetString("合同编号")
 	cell1.SetStyle(style)
 	cell2 := titleRow.AddCell()
-	cell2.SetString("开票金额")
+	cell2.SetValue(fmt.Sprintf("%s金额", listName))
 	cell2.SetStyle(style)
 	cell3 := titleRow.AddCell()
-	cell3.SetString("开票日期")
+	cell3.SetValue(fmt.Sprintf("%s日期", listName))
 	cell3.SetStyle(style)
 
 	for _, v := range list {
@@ -1424,7 +1451,7 @@ func (rg *RegisterController) InvoiceExport(c *gin.Context) {
 	_ = xlsxFile.Write(&buffer)
 	content := bytes.NewReader(buffer.Bytes())
 	randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
-	fileName := "开票列表_" + randStr + ".xlsx"
+	fileName := fmt.Sprintf("%s列表_%s.xlsx", listName, randStr)
 
 	c.Writer.Header().Add("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"`, fileName))
 	c.Writer.Header().Add("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")

+ 1 - 0
models/fms/contract_invoice.go

@@ -72,6 +72,7 @@ func (c *ContractInvoice) Fetch(id int) (item *ContractInvoice, err error) {
 func (c *ContractInvoice) Sum(field, condition string, pars []interface{}) (total float64, err error) {
 	totalList := make([]float64, 0)
 	err = global.DEFAULT_MYSQL.Model(c).
+		Where("is_deleted = 0").
 		Where(condition, pars...).
 		Pluck(field, &totalList).Error
 	for i := range totalList {